Jacobain with 3 functions

1 view (last 30 days)
am
am on 27 Mar 2019
Edited: madhan ravi on 27 Mar 2019
Hello,
Can someone help me to see what is wrong with my jacobian?
I reviewed it several time byt matlab still says there is a syntax error.
Additionally, why jacobian(f,x) does not work?
f=@(x) [3*x(1) - cos(x(2)*x(3)) - 3/2;
4*x(1)^2 - 625*x(2)^2 + 2*x(3) - 1;
20*x(3)^3 + exp(-1*(x(1)*x(2))) + 9]
J=@(x) [3, -1*(x(3)*cos(x(2)*x(3))), -1*(x(2)*cos(x(2)*x(3)));
8*x(1) , 1250*x(2), 2;
-1*(x(2)exp(-x(1)*x(2))), -1*(x(1)exp(-x(1)*x(2))), 20]
  2 Comments
am
am on 27 Mar 2019
I would also like to understand what is wrong with my syntax?
J=@(x) [3, -1.*(x(3).*cos(x(2)*x(3))), -1.*(x(2).*cos(x(2)*x(3)));
8*x(1) , 1250*x(2), 2;
-1*(x(2)exp(-x(1)*x(2))), -1*(x(1)exp(-x(1)*x(2))), 20]
madhan ravi
madhan ravi on 27 Mar 2019
Correct syntax would be:
J=@(x) [3, -1.*(x(3).*cos(x(2)*x(3))), -1.*(x(2).*cos(x(2)*x(3)));
8*x(1) , 1250*x(2), 2;
-1*(x(2)*exp(-x(1)*x(2))), -1*(x(1)*exp(-x(1)*x(2))), 20]

Sign in to comment.

Accepted Answer

madhan ravi
madhan ravi on 27 Mar 2019
Edited: madhan ravi on 27 Mar 2019
https://in.mathworks.com/help/symbolic/jacobian.html - the function has to have symbolic arguments as mentioned in the link above , where as what you created was a function handle (@(x)).
x = sym('x',[1 3]);
syms(x) % the reason I used this is even you can access the elements of the vector x as like x1 or x(1) unlike x = sym('x',[1,3]) where you can only access the elements as x(1) but not as x1!
f= [3*x(1) - cos(x(2)*x(3)) - 3/2;
4*x(1)^2 - 625*x(2)^2 + 2*x(3) - 1;
20*x(3)^3 + exp(-1*(x(1)*x(2))) + 9]
jacobian(f,x)
if you type
>> which jacobian -all
/Applications/MATLAB_R2018b.app/toolbox/symbolic/symbolic/@sym/jacobian.m % sym method
>>
It shows that jacobian() belongs to symbolic math toolbox.
  4 Comments
am
am on 27 Mar 2019
thank you <3
madhan ravi
madhan ravi on 27 Mar 2019
Edited: madhan ravi on 27 Mar 2019
If you just want to do the operation => J(x)\f(x) then
x = sym('x',[1 3]);
f(x) = [3*x(1) - cos(x(2)*x(3)) - 3/2 ;...
4*x(1)^2 - 625*x(2)^2 + 2*x(3) - 1 ;...
20*x(3)^3 + exp(-1*(x(1)*x(2))) + 9];
J(x) = [3 , -1.*(x(3).*cos(x(2)*x(3))), -1.*(x(2).*cos(x(2)*x(3))) ;...
8*x(1) , 1250*x(2) , 2 ;...
-1*(x(2)*exp(-x(1)*x(2))), -1*(x(1)*exp(-x(1)*x(2))) , 20 ];
Calculation = J\f;
Calculation(2,4,5)
% ^^^^^---- example values of x1 , x2 and x3 , this line of code indicates now you can substitute 3 values in the place of x1, x2 and x3
% you then double the result using double() for instance
double(Calculation(2,4,5))

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!