Borrar filtros
Borrar filtros

solve systems of linear equation in for loop

2 visualizaciones (últimos 30 días)
Andrew Poissant
Andrew Poissant el 9 de Abr. de 2017
Comentada: Andrew Poissant el 10 de Abr. de 2017
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

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Function Creation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by