The solve function doesn't work properly
1 view (last 30 days)
Show older comments
Hello everyone. I'm trying to solve an equation system. This particular system has variables that are functions of time, and when I try to use a loop to analyze them they don't acquire the correct values. However, if I do the same changing the time values manually it does work. Any idea why this is? Thanks in advance.
syms l1 l2 l3 H B phi gamma theta omega1 omega2 omega3 t beta
l1 = 0.124;
l2 = 0.27;
l3 = 0.095;
B = 0.238;
H = 0.117;
array_valores1 = zeros(1,30);
array_valores2 = zeros(1,30);
array_valores3 = zeros(1,30);
i = 0
t = 21
% while t < 31
gamma = pi -pi*t/40;
array_gamma(i+1) = pi -pi*t/40;
eq1 = l3*cos(gamma) - l2*cos(phi) + l1*sin(theta) + B == 0;
eq2 = l3*sin(gamma) - l2*sin(phi) -l1*cos(theta) + H == 0;
sol1 = solve([eq1 eq2], [theta phi]);
phi = vpa(sol1.phi(1))
theta = vpa(sol1.theta(1))
% i = i+1;
% end
0 Comments
Answers (1)
Torsten
on 20 Jan 2023
syms l1 l2 l3 H B phi gamma theta
eq1 = l3*cos(gamma) - l2*cos(phi) + l1*sin(theta) + B == 0;
eq2 = l3*sin(gamma) - l2*sin(phi) -l1*cos(theta) + H == 0;
sol = solve([eq1 eq2], [theta phi]);
t = 21:31;
theta_array = zeros(2,numel(t));
phi_array = zeros(2,numel(t));
for i = 1:numel(t)
theta_array(:,i) = double(subs(sol.theta,[l1 l2 l3 H B gamma],[0.124,0.27,0.095,0.117,0.238,pi*(1-t(i)/40)]));
phi_array(:,i) = double(subs(sol.phi,[l1 l2 l3 H B gamma],[0.124,0.27,0.095,0.117,0.238,pi*(1-t(i)/40)]));
end
figure(1)
plot(t,theta_array)
grid on
figure(2)
plot(t,phi_array)
grid on
0 Comments
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!