I need help with Symbolic Differentiation Error
1 次查看(过去 30 天)
显示 更早的评论
Hello MATLAB community,
I am trying to do partial differentiation to find a 6x3 (Jr) matrix, but I am getting an error which says:
" Second argument must be a variable or a nonnegative integer specifying the number of differentiations."
I tried to play around by changing the code, but the problem is still the same.
Below is my code:
syms phi theta psi Psi
h = 110.75;
d2r = pi/180;
r2d = 180/pi;
ROT = [(cos(phi)*cos(psi))-(cos(theta)*sin(phi)*sin(psi)) -(cos(phi)*sin(psi))-(cos(theta)*cos(psi)*sin(phi)) (sin(phi)*sin(theta));...
(cos(psi)*sin(phi))+(cos(phi)*cos(theta)*sin(psi)) (cos(phi)*cos(theta)*cos(psi)-sin(phi)*sin(psi)) -(cos(phi)*sin(theta));...
(sin(theta)*sin(psi)) (cos(psi)*sin(theta)) cos(theta)];
px = (h/2)*(ROT(1,1)-ROT(2,2));
py = -h*ROT(2,1);
eqn = ROT(1,2) == ROT(2,1);
Psi = eqn;
pz = input('Please enter value for pz: ');
phi = input('Please enter value for phi: ')*d2r;
theta = input('Please enter value for theta: ')*d2r;
if phi >= 0
psi = -phi ;
elseif phi <= 0
psi = -phi ;
end
jr = [diff(px, pz), diff(px, phi), diff(px, theta); diff(py, pz), diff(py, phi), diff(py, theta); 1, 0, 0; 0, 1, 0; 0, 0, 1; diff(Psi, pz), diff(Psi, phi), diff(Psi, theta)];
Jr = double(subs(jr,{phi,theta,psi},{phi,theta,psi}))
You can assume the values for pz, phi, theta to be 435, 5, and 10, respectively.
Can anyone please help me with this problem.
Kind regards,
Shiv
0 个评论
采纳的回答
Dyuman Joshi
2023-2-20
编辑:Dyuman Joshi
2023-2-20
You are over-writing the symboic variables, psi and theta by taking input from the user. Rename the variables which you will use for substitution
Also, the if-else condition block seems redundant, as regardless of the value of phi, psi = -phi
syms phi theta psi Psi
h = 110.75;
d2r = pi/180;
r2d = 180/pi;
ROT = [(cos(phi)*cos(psi))-(cos(theta)*sin(phi)*sin(psi)) -(cos(phi)*sin(psi))-(cos(theta)*cos(psi)*sin(phi)) (sin(phi)*sin(theta));...
(cos(psi)*sin(phi))+(cos(phi)*cos(theta)*sin(psi)) (cos(phi)*cos(theta)*cos(psi)-sin(phi)*sin(psi)) -(cos(phi)*sin(theta));...
(sin(theta)*sin(psi)) (cos(psi)*sin(theta)) cos(theta)];
px = (h/2)*(ROT(1,1)-ROT(2,2));
py = -h*ROT(2,1);
eqn = ROT(1,2) == ROT(2,1);
Psi = eqn;
pz = 435; %input('Please enter value for pz: ');
phi0 = 5; %input('Please enter value for phi: ')*d2r;
theta0 = 10; %input('Please enter value for theta: ')*d2r;
if phi0 >= 0
psi0 = -phi0 ;
elseif phi0 <= 0
psi0 = -phi0 ;
end
jr = [diff(px, pz), diff(px, phi), diff(px, theta); diff(py, pz), diff(py, phi), diff(py, theta); 1, 0, 0; 0, 1, 0; 0, 0, 1; diff(Psi, pz), diff(Psi, phi), diff(Psi, theta)];
Jr = double(subs(jr,{phi,theta,psi},{phi0,theta0,psi0}))
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!