Ode45 and initial conditions

조회 수: 6 (최근 30일)
gbernardi
gbernardi 2011년 10월 29일
댓글: Jan 2016년 2월 29일
Hello everybody, I'm using the MATLAB ode solver ode45 to numerically solve some easy differential equations.
I got how to use this tool, but there are some situations that left me a bit puzzled.
Say, I have the differential equation:
y'(x) = f(y,x)
and I want to solve it in a range (a,b) using the initial condition
y(c) = k
with k,c being constants and
a<c<b.
How can I say to the solver that my initial condition is not in the point a, but in the point c (according to the help, once one provides the time span in ode45, the initial condition is automatically assigned to the initial point of it)?
I solved the problem splitting the interval in 2 parts
(a,c) and (c,b)
and calling the solver twice (apparently ode45 works backward just as fine as it works forward :D). The solution is correct in this way but i find the method a bit lumbering (let's say I'd have expected MATLAB doing that for me automatically ;)
Any suggestion on a more elegant use of ode45?
Thank you in advance!
Giuliano

채택된 답변

Jan
Jan 2011년 10월 29일
This is the best solution. It is the standard case that the "initial condition" concerns the initial time.
If you want a "nicer" solution, you can create a wrapper:
function [y, t] = ODE45_intermediateStart(Fcn, a, b, c)
Then you can insert the two calls to ODE45 and join the outputs.
  댓글 수: 2
jatinder goyal
jatinder goyal 2016년 2월 22일
Can you please elaborate the answer? I didn't understood what you said.
Jan
Jan 2016년 2월 29일
@jatinder goyal: My suggestion was almost trivial, because the OP found an efficient solution already. The problem was to integrate from a < c < b, and the conditions are known for the time c. The solution is to integrate 2 times: 1. from c to b, and 2. from c to a. I only added the idea, that these 2 calls of ODE45 can be wrapped inside another function, which might look a little bit nicer in the main program.

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

추가 답변 (1개)

gbernardi
gbernardi 2011년 10월 30일
Thanks for the reply Jan! Cheers

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by