Clear Filters
Clear Filters

Converting from symbolic to numerical data

1 view (last 30 days)
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)])
Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
angB = 
angD = 
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)
angB = 
angD = simplify(angD)
angD = 
angulardisp1 = double(angB)
angulardisp1 = 2×1
1.0024 -0.0194
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.

Accepted Answer

John D'Errico
John D'Errico on 7 Nov 2023
Edited: John D'Errico on 7 Nov 2023
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
SIN Sine of argument in radians. SIN(X) is the sine of the elements of X. See also ASIN, SIND, SINPI. Documentation for sin doc sin Other uses of sin codistributed/sin fixedpoint/sin sym/sin tabular/sin dlarray/sin gpuArray/sin symbolic/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 Comment
Cris LaPierre
Cris LaPierre on 7 Nov 2023
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)]);
Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
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)
angD = 
angulardisp1 = double(angB)
angulardisp1 = 2×1
35.1162 -82.7042

Sign in to comment.

More Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!