필터 지우기
필터 지우기

Time varying force with ode23

조회 수: 2 (최근 30일)
Christo van Rensburg
Christo van Rensburg 2020년 4월 25일
댓글: Christo van Rensburg 2020년 4월 25일
Hi there
I have the following code:
tf = 1;
t = linspace(0,3);
Ft = zeros(length(t),1);
% Here I generate the force values at different time intervals.
for i = 1:length(t)
if t(i) <= tf
Ft(i) = Fo*sin(2*pi*t(i)/tf);
elseif t(i) > tf
Ft(i) = 0;
end
end
ic = [0, 0]; % Initial conditions
dXdt = @(t, x) [x(2);
Ft * 1/(m1+m2)];
[t, x] = ode23(dXdt, [0, 3], ic);
I'm struggling to incorportate this time varying force F(t) into the ode23 function.
Any help as to how I can maybe get this done?
Thanks in advance!

채택된 답변

darova
darova 2020년 4월 25일
Use function handle
Ft = @(t) (t<=tf)*Fo*sin(2*pi*t/tf);
dXdt = @(t, x) [x(2);
Ft(t) * 1/(m1+m2)];
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 4월 25일
That would work if the driving force was not discontinuous.
Christo van Rensburg
Christo van Rensburg 2020년 4월 25일
It seems to work though.
Walter I'll try your method now, because what you're saying makes sense.
Thanks for the help!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2020년 4월 25일
You cannot do that the way you want. The ode* routines cannot handle discontinuities in the driving functions. You need to break it up into two time periods, one with the force and one without the force.
tf = 1;
dXdt_F = @(t, x) [x(2); Fo*sin(2*pi*t/tf) / (m1+m2)];
dXdt_NF = @(t, x) [x(2); 0];
ic = [0, 0]; % Initial conditions
[t1, x1] = ode23(dXdt_F, [0, tf], ic);
ic2 = x1(end,:);
[t2, x2] = ode23(dXdt_NF, [tf, 3], ic2);
t = [t1; t2(2:end)];
x = [x1; x2(2:end,:)];
  댓글 수: 1
Christo van Rensburg
Christo van Rensburg 2020년 4월 25일
Both methods seem to work fine.
Thanks guys.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by