- If tspan has two elements, [t0 tf], then the solver returns the solution evaluated at each internal integration step within the interval.
- If tspan has more than two elements [t0,t1,t2,...,tf], then the solver returns the solution evaluated at the given points. However, the solver does not step precisely to each point specified in tspan. Instead, the solver uses its own internal steps to compute the solution, then evaluates the solution at the requested points in tspan. The solutions produced at the specified points are of the same order of accuracy as the solutions computed at each internal step.Specifying several intermediate points has little effect on the efficiency of computation, but for large systems it can affect memory management.
MATLAB event function for ODE, specifying time span, and obtaining solution
31 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Taehun Kim
am 4 Jan. 2021
Kommentiert: Taehun Kim
am 4 Jan. 2021
Hello All,
Warm regards for all and hope you all have a great 2021!
So, in my research project, I am using MATLAB ode45 to integrate some ODEs. I am also using event function to terminate the integration.
The problem that I am having is that I want to have a consistent number of time points and corresponding state soluitions regardless of the time span I provide to ode45.
In general, to be safe, i.e. to make sure that an event happens, I am using a very conservative time span as an input. However, while the event happens, I am getting a very few number of solutions out.
I heard that there are some interpolation functions that allows one to obtain solutions from ode45 at a specified time points but I am not sure how to pass the information from the ode solver to the interpolating function other than a few number of ode solutions. There may be just one single point in certain case...
So basically, are there ways to ensure that (1) the event will happen within a given time span other than being conservative with time span, and (2) can I obtain many time points and corresponding solutions even if the returen ode solutions only contains a few points that are in the range that I want the solution for (i.e. from initial time to an event time)?
Thank you so much for your help!
0 Kommentare
Akzeptierte Antwort
Cris LaPierre
am 4 Jan. 2021
If you specify a vecor of times for your tspan instead of start and end time, MATLAB will still solve the ode the same, but will return results for the time points you specified. From the tspan input argument definition on the ode45 documentation page.
7 Kommentare
Steven Lord
am 4 Jan. 2021
You can call the ODE solver with one output which will be a solution structure. You can pass that structure into deval to evaluate that solution at a list of times that you also pass into deval. The red circles below are the points ode45 computed, the black + symbols are the points computed by deval.
sol = ode45(@(t, y) y, [0 2], 1);
tt = 0:0.125:2;
plot(sol.x, sol.y, 'ro', tt, deval(sol, tt), 'k+-')
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!