Jacobain with 3 functions

1 回表示 (過去 30 日間)
am
am 2019 年 3 月 27 日
編集済み: madhan ravi 2019 年 3 月 27 日
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 件のコメント
am
am 2019 年 3 月 27 日
thank you <3
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 Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by