Write the nonlinear system
$x_1^3-2x^2=2$
$x_1^3-5x_3^2=-7$
$x_2x_3^2=1$
in the form $f(x)=0$.
Compute the Jacobian J(x).
Create the files sys.m and sys_jac.m that take as a argument a 3-dimensional column vector $x$ and return $f(x)$ and the Jacobian $J(x)$.
I'm pretty new to matlab, and I also don't understand some of the wording in this request ("sys.m and sys_jac.m that take as a argument a 3-dimensional column vector x and return f(x) and the Jacobian J(x)"
I tried putting in the sys.m
function result=sys(x)
f = inline ( '[x(1)^3-2*x(2)-2 ; x(1)^3-5*x(3)^2+7; x(2)*x(3)^2-1] ');
end
and sys_jac.m
function result = sys_jac(x)
j=jacobian([[x(1)^3-2*x(2)-2 ; x(1)^3-5*x(3)^2+7; x(2)*x(3)^2-1]], [x(1), x(2), x(3)]);
end
but nothing really works and I still don't exactly understand what is the request of this program?
In Matlab, you define a function like this:
If there is only one output, you may write simply
But you must of course assign a value to the output variable. Then, when you call the function somewhere, you may write
(that's from memory, since I have not worked with Matlab since 2004, but it should be correct)