ODE using different initial conditions at one time point

4 次查看(过去 30 天)
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