Converting from symbolic to numerical data
2 次查看(过去 30 天)
显示 更早的评论
I tried using double to convert from symbolic to numerical data but it is giving me the wrong answer.
syms A B C D theta(t) omega1(t) alpha1(t) t
assume([A B C D],"real")
Displacement analysis
syms beta(t) phi(t)
%for equilibrium, sum of displacement component on x and y axis must
%respectively be equal to zero
xdisp = A*cos(theta) + B*cos(beta) - C*cos(phi) - D == 0;
ydisp = A*sin(theta) + B*sin(beta) - C*sin(phi) == 0;
[angB,angD] = solve([xdisp,ydisp],[beta(t),phi(t)])
angB = simplify(angB);
angD = simplify(angD);
Velocity analysis
xvel = diff(xdisp,t);
yvel = diff(ydisp,t);
syms omega2(t) omega3(t)
xvel = subs(xvel,[diff(beta(t), t),diff(phi(t), t),diff(theta(t), t)],[omega2(t),omega3(t),omega1(t)]);
yvel = subs(yvel,[diff(beta(t), t),diff(phi(t), t),diff(theta(t), t)],[omega2(t),omega3(t),omega1(t)]);
[velB,velD] = solve([xvel,yvel],[omega2(t),omega3(t)]);
velB = simplify(velB);
velD = simplify(velD);
Acceleration analysis
xacc = diff(xvel,t);
yacc= diff(yvel,t);
syms alpha2(t) alpha3(t)
xacc = subs(xacc,[diff(omega1(t),t),diff(omega2(t),t),diff(omega3(t),t),diff(beta(t),t),diff(phi(t),t),diff(theta(t),t)],[alpha1(t),alpha2(t),alpha3(t),omega2(t),omega3(t),omega1(t)]);
yacc = subs(yacc,[diff(omega1(t),t),diff(omega2(t),t),diff(omega3(t),t),diff(beta(t),t),diff(phi(t),t),diff(theta(t),t)],[alpha1(t),alpha2(t),alpha3(t),omega2(t),omega3(t),omega1(t)]);
[accB,accD] = solve([xacc,yacc],[alpha2(t),alpha3(t)]);
accB = simplify(accB);
accD = simplify(accD);
Numerical values of the displacement, velocity and acceleration
angB = subs(angB,[A B C D theta(t) omega1(t) alpha1(t)],[300 360 360 600 30 10 -30]);
angD = subs(angD,[A B C D theta(t) omega1(t) alpha1(t)],[300 360 360 600 30 10 -30]);
angB = simplify(angB)
angD = simplify(angD)
angulardisp1 = double(angB)
If i use calculator to check th answer of angB it gives 35.12 which is correct but if i use double to convert the symbolic data to numerical data it gives 1.0024 which is wrong.
0 个评论
采纳的回答
John D'Errico
2023-11-7
编辑:John D'Errico
2023-11-7
Do you understand that sin and cos assume RADIANS, NOT degrees? But you are substituting in angles that are clearly in terms of DEGREES.
angB = subs(angB,[A B C D theta(t) omega1(t) alpha1(t)],[300 360 360 600 30 10 -30]);
There is a difference, and it is important.
help sin
MATLAB cannot know that you think of angles in terms of degrees, since it cannot read your mind. Even after all these years, the mindreading toolbox is still in the debugging phase.
You can convert degrees to radians by multiplying by pi/180, or you can use the deg2rad function to do it for you. For example, 30 degrees is pi/6 radians.
1 个评论
Cris LaPierre
2023-11-7
To add on to this answer, either substitute radian degress, or use cosd and sind to define xdisp and ydisp.
syms A B C D theta(t) omega1(t) alpha1(t) t
assume([A B C D],"real")
syms beta(t) phi(t)
%for equilibrium, sum of displacement component on x and y axis must
%respectively be equal to zero
xdisp = A*cosd(theta) + B*cosd(beta) - C*cosd(phi) - D == 0;
ydisp = A*sind(theta) + B*sind(beta) - C*sind(phi) == 0;
[angB,angD] = solve([xdisp,ydisp],[beta(t),phi(t)]);
angB = simplify(angB);
angD = simplify(angD);
xvel = diff(xdisp,t);
yvel = diff(ydisp,t);
syms omega2(t) omega3(t)
xvel = subs(xvel,[diff(beta(t), t),diff(phi(t), t),diff(theta(t), t)],[omega2(t),omega3(t),omega1(t)]);
yvel = subs(yvel,[diff(beta(t), t),diff(phi(t), t),diff(theta(t), t)],[omega2(t),omega3(t),omega1(t)]);
[velB,velD] = solve([xvel,yvel],[omega2(t),omega3(t)]);
velB = simplify(velB);
velD = simplify(velD);
xacc = diff(xvel,t);
yacc= diff(yvel,t);
syms alpha2(t) alpha3(t)
xacc = subs(xacc,[diff(omega1(t),t),diff(omega2(t),t),diff(omega3(t),t),diff(beta(t),t),diff(phi(t),t),diff(theta(t),t)],[alpha1(t),alpha2(t),alpha3(t),omega2(t),omega3(t),omega1(t)]);
yacc = subs(yacc,[diff(omega1(t),t),diff(omega2(t),t),diff(omega3(t),t),diff(beta(t),t),diff(phi(t),t),diff(theta(t),t)],[alpha1(t),alpha2(t),alpha3(t),omega2(t),omega3(t),omega1(t)]);
[accB,accD] = solve([xacc,yacc],[alpha2(t),alpha3(t)]);
accB = simplify(accB);
accD = simplify(accD);
angB = subs(angB,[A B C D theta(t) omega1(t) alpha1(t)],[300 360 360 600 30 10 -30]);
angD = subs(angD,[A B C D theta(t) omega1(t) alpha1(t)],[300 360 360 600 30 10 -30]);
angB = simplify(angB);
angD = simplify(angD)
angulardisp1 = double(angB)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!