while in ode45

조회 수: 2 (최근 30일)
Arnab
Arnab 2024년 11월 30일
댓글: Arnab 2024년 12월 1일
Let me solve an ODE .
dy/dt=y.
y(0)=1.
Now i want to just solve the ODE for 5 seconds. Let y(5) denote the value of state 'y' at time =5.
At t=5 I want to update the initial condition as: y(5)=0.5*y(5) and again solve the given ODE for next 10 seconds.
I want to use while statement for this work. Can I do that ? If yes, please provide some outline of the code.
Thanks
  댓글 수: 2
James Tursa
James Tursa 2024년 11월 30일
What have you done so far? What specific problems are you having with your code? Can you code up the first part, without any while loop, to just solve for the first 5 seconds?
Arnab
Arnab 2024년 11월 30일
Actually I was solving solving some different problem where I need this concept. Can you please solve the above ODE that will help me out, u think.

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

채택된 답변

Cris LaPierre
Cris LaPierre 2024년 11월 30일
One of your inputs to ode45 is tspan. If I were going to do this, I would look at building is so that my loop calls ode45 with the desired inputs rather than trying to do it inside the odefcn.
Here is an outline (untested)
y0 = 0;
tspan = [0 5;5 15]
y_out = [];
for ts = 1:sizse(tspan,1));
[t,y] = ode45(odefcn,tspan(ts,:),y0);
y0 = o.5*y(end);
y_out = [y_out;y];
end
  댓글 수: 9
Torsten
Torsten 2024년 12월 1일
As you are a beginner in MATLAB, use MATLAB Onramp to learn the basics of the new language:
Concerning your question, it will help to study the "ballode" example here:
Arnab
Arnab 2024년 12월 1일
Ok, thank u for the help.

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

추가 답변 (0개)

카테고리

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