solve systems of linear equation in for loop

1 次查看(过去 30 天)
I want to solve a system of 3 equations, all of which are in a for loop. Is there any way to solve for [dx, dy, dt] 180 times and get all of those values?
syms dx dy dt
ax = 0;
ay = 0;
az = -9.8;
u = 16;
phi = 0;
h1 = 60.96;
h2 = 0;
dz = h1 - h2;
for theta = 1:180;
u_x(theta) = u*cosd(theta)*cosd(phi);
u_y(theta) = u*sind(theta)*cosd(phi);
u_z(theta) = u*sind(phi);
f1 = dx(theta) == u_x(theta)*dt + 0.5*ax*dt^2;
f2 = dy(theta) == u_y(theta)*dt + 0.5*ay*dt^2;
f3 = dz(theta) == -u_z(theta)*dt + 0.5*az*dt^2;
[dx, dy, dt] = solve([f1, f2, f3], [dx, dy, dt]);
end

采纳的回答

Torsten
Torsten 2017-4-10
ax = 0;
ay = 0;
az = -9.8;
u = 16;
phi = 0;
h1 = 60.96;
h2 = 0;
dz = h1 - h2;
theta = 1:1:180;
u_x = u*sind(theta)*cosd(phi);
u_y = u*sind(theta)*cosd(phi);
u_z = u*sind(phi);
dt = u_z/az + sqrt(u_z.^2+2*dz*az)/az; (or dt = u_z/az - sqrt(u_z.^2+2*dz*az)/az;)
dx = u_x.*dt + 0.5*ax*dt.^2;
dy = u_y.*dt + 0.5*ay*dt.^2;
Best wishes
Torsten.
  1 个评论
Andrew Poissant
Andrew Poissant 2017-4-10
Thanks! I guess I was overcomplicating things. Just had to solve in terms of dt first

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by