Problem with solve and syms array to have numerical results

Hello,
I would like to see numerical results, with solve and sims arrays, but it doesn't work. Here is my code. My problem concerns the last lines from "%Inconnues"
clear
clc
close all
% Valeur accélération mm/s², vitesse mm/s, temps total s, position initial rad, position final rad
a=14.77/2;
v=14.77;
T=12;
X0=0;
XT=pi/2;
a=(a*90/147.7)*(pi/180);
v=(v*90/147.7)*(pi/180);
% vecteur t
t=0:(10^(-1)):T;
% Accélération angulaire A :
A=zeros(1,T*10^(1)+1);
for n=1 : ((v/a)*10^(1)+1)
A(1,n) = a;
end
for n=(length(t)-round(v/a)*10^(1)) : (length(t))
A(1,n)= -a;
end
%Vitesse angulaire V :
V=zeros(1,T*10^(1)+1);
for n=1 : (round((v/a)*10^(1))+1)
V(1,n) = a*t(1,n);
end
for n=(round((v/a)*10^(1))+1+1) : (length(t)-round((v/a)*10^(1))-1)
V(1,n) = v;
end
for n=(length(t)-round((v/a)*10^(1))) : (length(t))
V(1,n)= (v+a*t(1,(length(t)-round((v/a)*10^(1))))) -a*t(1,n);
end
%Déplacement angulaire X :
X=zeros(1,T*10^(1)+1);
for n=1 : (round((v/a)*10^(1))+1)
X(1,n) = a*t(1,n)^(2)/2;
end
for n=(round((v/a)*10^(1))+1+1) : (length(t)-round((v/a)*10^(1))-1)
X(1,n) = v*t(1,n)-(v^(2)/(2*a));
end
for n=(length(t)-round((v/a)*10^(1))) : (length(t))
X(1,n)= (v+a*t(1,(length(t)-round((v/a)*10^(1)))))*t(1,n) -(a*t(1,n)^(2)/2)+(XT+(a*T^(2)/2)-(v+a*t(1,(length(t)-round((v/a)*10^(1)))))*T);
end
% Vecteurs OA, OB et OG
Xoa=96*10^(-3);
Yoa=46*10^(-3);
Xob=350*10^(-3);
Yob=23*10^(-3);
Xog=257.69*10^(-3);
Yog=24.53*10^(-3);
% Masse et moment d'inertie
m=24.9;
Iz=2.36;
g=9.81;
%angle Phi
Z=-asin((Xoa*sin(X)+Yoa*cos(X)-Yob)/sqrt(-sin(X)*(2*Xoa*Yob-2*Xob*Yoa)-cos(X)*(2*Xoa*Xob+2*Yoa*Yob)+Xoa^(2)+Xob^(2)+Yoa^(2)+Yob^(2)));
%Inconnues:
X01=sym('X01',[1 121]);
Y01=sym('Y01',[1 121]);
F21=sym('F21',[1 121]);
%Sommes forces et moments
%x
Xf=X01+F21.*cos(Z);
%y
Yf=Y01+F21.*sin(Z)-m*g;
%z
Zf=F21.*sin(Z).*(Xoa.*cos(X)-Yoa.*sin(X))-F21.*cos(X).*(Yoa.*cos(X)+Xoa.*sin(X))-(Xog.*cos(X)-Yog.*sin(X)).*m.*g;
%Torseur dynamique
%x
Xd=-Xog.*(A.*sin(X)+V.^(2).*cos(X))+Yog.*(-A.*cos(X)+V.^(2).*sin(X));
%y
Yd=Xog.*(A.*cos(X)-V.^(2).*sin(X))-Yog.*(A.*sin(X)+V.^(2).*cos(X));
%z
Zd=Iz.*A;
%PFD
eqn1= Xf==Xd;
eqn2= Yf==Yd;
eqn3= Zf==Zd;
sol=solve([eqn1 eqn2 eqn3],[F21 X01 Y01]);
I would like to have the numerical values of F21 X01 and Y01.
I tried with
double(subs(F21))
vpa(F21)
sol=vpasolve([eqn1 eqn2 eqn3],[F21 X01 Y01])
but it didn't work.
If I call F21 it gives me
F21 =
[F211, F212, F213, F214, F215, F216, --- , F21117, F21118, F21119, F21120, F21121]
>> F21(1,1)
ans =
F211
If I call sol it gives me
sol =
struct with fields:
F211: [1×1 sym]
F212: [1×1 sym]
F213: [1×1 sym]
F214: [1×1 sym]
F215: [1×1 sym]
F216: [1×1 sym]
F217: [1×1 sym]
-------------
Y01116: [1×1 sym]
Y01117: [1×1 sym]
Y01118: [1×1 sym]
Y01119: [1×1 sym]
Y01120: [1×1 sym]
Y01121: [1×1 sym]
The only solution that I find to have value is
sol.F211
ans =
-967.60287385780605423753073081481
but I want all the values and when I do
sol.F21(1,1)
It doesn't work again.
I didn't use matlab for a long time, so it's probably a silly mistake.
Can someone help me please ?
Many thanks in advance for your help.

 Accepted Answer

I find the solution of my problem. If someone as the same problem you can try this :
To start, declare all the variables as syms
Then, use solve (equal to something)
After that, you can assign numerical values to the variables.
To finish, evaluate the solutions.
Here is an exemple :
syms X1 Y1 Z1 X2 Y2 Z2 a b c;
eqn1= X1.*Z1==a;
eqn2= Y1-Z2==b;
eqn3= X2./Y2==c;
sol=solve([eqn1 eqn2 eqn3],[a b c])
X1=3;
Y1=-8;
Z1=1:1:1000
.......
a=eval(sol.a)
b=eval(sol.b)
c=eval(sol.c)

More Answers (0)

Products

Release

R2020b

Asked:

on 30 Mar 2021

Answered:

on 31 Mar 2021

Community Treasure Hunt

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

Start Hunting!