How do I use the results from previous loop in a new loop to generate results?

1 visualización (últimos 30 días)
This are the loop used to solve my ODE second order ODE which is working fine.
Currently, my code work fine with the constant w (frequency).
Now i would like to use to the rms of x generated from the ODE and plot against a range of w.
So for each w, i would only get a rms of x . By ruunning multiple times of different w , multiple rms of x could be generated to plot RAO .
Any idea how to do so?
for t = 2:1:1600
time(t) = dt*t - dt; % Time in seconds
for w= 0.1 : 0.1 : 2
f(t) = a*sin(w*(time(t))); % Forcing expression/function
end
opt = odeset('RelTol',1e-5,'AbsTol',1e-5);
[~,XX] = ode45(@rhs,[0 dt],[x(t-1) v(t-1)],opt,[f(t) m b k v1 m1 ]);
x(t) = XX(end,1);
v(t) = XX(end,2);
end
  1 comentario
Jan
Jan el 22 de Mzo. de 2021
Providing parameters as final argument of ODE45 is outdated since nearly 20 years now. Use anaonymous functions instead: Answers: Anonymous for params
So for each w, i would only get a rms of x - This is not clear. Why do you create f(t) inside the for t loop repeatedly? You are overwriting f(t) inside the for w loop.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by