How do I use the results from previous loop in a new loop to generate results?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jan
2021-3-22
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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!