Why the seond arugment in the command jacobian is not a vector of variables?
16 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Tony Cheng
il 9 Apr 2019
Modificato: Walter Roberson
il 11 Apr 2023
Hi guys, I am using the code Jacobian in Matlab to symbolically compute the Jacobian matrix for two vectors-A and B.
These two vectors are defined by some symbolic variables and they are all functions of the variable t as follows:
syms t a1(t) a2(t) a3(t) b1(t) b2(t) b3(t)
A = [a1(t) ; a2(t) ; a3(t) ] ;
B = [b1(t) ; b2(t) ; b3(t) ] ;
What I did is C = jacobian(A , B ) .
However, Matlab gives an error to me and says the second argument must be a vector of variables.
I am very confused: the second argument B is obviously 3 times 1 symbolic vector. Why the code is not write?
Can anyone offer me some solutions?
Many thanks!
0 Commenti
Risposta accettata
Stephan
il 9 Apr 2019
Modificato: Stephan
il 9 Apr 2019
Hi,
you declare b1...b3 as symbolic functions of t - not as symbolic variables. Thats why it doesnt work.
Here is an example:
syms a1(t) a2(t) a3(t) b1 b2 b3
a1(t) = b1*sin(t)/(b2+b3);
a2(t) = 3*t + 5/b2+b3;
a3(t) = 4/t^b3-b1;
A = [a1 a2 a3] ;
B = [b1; b2; b3];
C = jacobian(A ,B)
results in:
C(t) =
[ sin(t)/(b2 + b3), -(b1*sin(t))/(b2 + b3)^2, -(b1*sin(t))/(b2 + b3)^2]
[ 0, -5/b2^2, 1]
[ -1, 0, -(4*log(t))/t^b3]
See the different symbolic types in this simple example:
>> syms a(t) b
>> whos
Name Size Bytes Class Attributes
a 1x1 8 symfun
b 1x1 8 sym
t 1x1 8 sym
Best regards
Stephan
3 Commenti
Stephan
il 9 Apr 2019
Modificato: Walter Roberson
il 11 Apr 2023
Why do you want to do this? Can you explain the context?
Here is a little dirty workaround, that lets you have all the b's as functions of t:
syms a1(t) a2(t) a3(t) b1(t) b2(t) b3(t)
a1(t) = b1(t)*sin(t) + b2 - b3;
a2(t) = b2(t)*cos(t) + 2*b3*b1;
a3(t) = b3(t)*3*t^2 - b2^2;
A(1:3) = [a1 a2 a3]
B(1:3) = [b1 b2 b3]
C_help = sym(zeros(3));
for ii = 1:3
C_help(ii,:) = functionalDerivative(A(ii),B);
end
C(t) = C_help
gives:
A =
[ b2(t) - b3(t) + b1(t)*sin(t), 2*b1(t)*b3(t) + b2(t)*cos(t), 3*t^2*b3(t) - b2(t)^2]
B =
[ b1(t), b2(t), b3(t)]
C(t) =
[ sin(t), 1, -1]
[ 2*b3(t), cos(t), 2*b1(t)]
[ 0, -2*b2(t), 3*t^2]
To check the results we use jacobian - where b1...b3 can not be functions of t, but variables:
syms a11(t) a22(t) a33(t) b11 b22 b33
a11(t) = b11*sin(t) + b22 - b33;
a22(t) = b22*cos(t) + 2*b33*b11;
a33(t) = b33*3*t^2 - b22^2;
AA = [a11 a22 a33]
BB = [b11 b22 b33]
CC = jacobian(AA,BB)
which is:
AA(t) =
[ b22 - b33 + b11*sin(t), 2*b11*b33 + b22*cos(t), - b22^2 + 3*b33*t^2]
BB =
[ b11, b22, b33]
CC(t) =
[ sin(t), 1, -1]
[ 2*b33, cos(t), 2*b11]
[ 0, -2*b22, 3*t^2]
So the given workaround appears to give correct results, including b1...b3 to be functions of t.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!