The solve function doesn't work properly

1 次查看(过去 30 天)
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

回答(1 个)

Torsten
Torsten 2023-1-20
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]);
Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
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

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by