Filter löschen
Filter löschen

ODE using different initial conditions at one time point

3 Ansichten (letzte 30 Tage)
Lucy
Lucy am 27 Jan. 2011
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 Kommentare
Doug Eastman
Doug Eastman am 28 Jan. 2011
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 am 28 Jan. 2011
What I tried was to find a ode solusion for a matrix and my supervisor just told me ode only took vectors.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Michael
Michael am 12 Apr. 2011
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.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by