필터 지우기
필터 지우기

ODE using different initial conditions at one time point

조회 수: 3 (최근 30일)
Lucy
Lucy 2011년 1월 27일
ode(function, tspan, x0) is to find the ode at one time point at the initial condition for this function first and goes to the next time point.
I need to produce a matrix at this time point with the ode result for this function in rows and two different initial conditions in columns.
And next time point the value of the matrix related to previous time point.
Any suggestions?
  댓글 수: 2
Doug Eastman
Doug Eastman 2011년 1월 28일
Are you saying that you want to run the ODE twice with 2 different sets of initial conditions and then have the output as two columns of an array?
Lucy
Lucy 2011년 1월 28일
What I tried was to find a ode solusion for a matrix and my supervisor just told me ode only took vectors.

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

답변 (1개)

Michael
Michael 2011년 4월 12일
You need to be careful with tspan as well. Some ODE functions give non-uniform spacing in time, and with different boundary conditions that spacing can be non-identical.
I would do something like this:
[t1,y1]=ode45('myfun',tspan,bc_one)
[t2,y2]=ode45('myfun',t1,bc_two)
Y=[y1', y2']
Where the time-output from the first becomes the sampling times for the second.
If you wanted to embed it in a loop you might do something like
N = myloops; %how many loops
tspan=linspace(mymin, mymax, mylength); %time sampling
Y=zeros(myloops,mylength); %pre-declare array
for i=1:N
[~,Y(i,:)]=ode45('myfun',tspan,BC(i,:))
end
You will have to have pre-declared the BC variable, and might do well to benchmark it against functions you know analytic solutions for, just to be sure you are okay with it. You may want to change the ode type (ode23s, or odde115 or whatever) depending on the nature of your problem. If you have a very stiff equations you might need a compatible solver. If that is the case you might want to have some finer granularity of time-stepping, or other tricks to adequately capture the phenomenology.

카테고리

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