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!