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

조회 수: 1 (최근 30일)
erwin ang
erwin ang 2021년 3월 22일
댓글: Jan 2021년 3월 22일
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
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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by