Clear Filters
Clear Filters

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

1 view (last 30 days)
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 Comment
Jan
Jan on 22 Mar 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.

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!