solve systems of linear equation in for loop

3 views (last 30 days)
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

Accepted Answer

Torsten
Torsten on 10 Apr 2017
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 Comment
Andrew Poissant
Andrew Poissant on 10 Apr 2017
Thanks! I guess I was overcomplicating things. Just had to solve in terms of dt first

Sign in to comment.

More Answers (0)

Categories

Find more on Function Creation 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!