Jacobain with 3 functions

1 次查看(过去 30 天)
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 个评论
am
am 2019-3-27
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 2019-3-27
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]

请先登录,再进行评论。

采纳的回答

madhan ravi
madhan ravi 2019-3-27
编辑:madhan ravi 2019-3-27
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 个评论
madhan ravi
madhan ravi 2019-3-27
编辑:madhan ravi 2019-3-27
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))

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by