Jacobain with 3 functions

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 comentarios

am
am el 27 de Mzo. de 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 el 27 de Mzo. de 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]

Iniciar sesión para comentar.

 Respuesta aceptada

madhan ravi
madhan ravi el 27 de Mzo. de 2019
Editada: madhan ravi el 27 de Mzo. de 2019

0 votos

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 comentarios

am
am el 27 de Mzo. de 2019
Editada: am el 27 de Mzo. de 2019
Thank you!
OK, this is weird, for it works in the command window but not in the live script
I get:
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
madhan ravi
madhan ravi el 27 de Mzo. de 2019
Editada: madhan ravi el 27 de Mzo. de 2019
Upload the code that you are trying in live script.
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]
% ^------ missing ^----- missing
am
am el 27 de Mzo. de 2019
thank you <3
madhan ravi
madhan ravi el 27 de Mzo. de 2019
Editada: madhan ravi el 27 de Mzo. de 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))

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

am
el 27 de Mzo. de 2019

Editada:

el 27 de Mzo. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by