Solving ODE in MATLAB with pre-defined steps

1 visualizzazione (ultimi 30 giorni)
Johannsen
Johannsen il 22 Ott 2022
Modificato: Johannsen il 23 Ott 2022
Hello,
I would like to solve an ordinary differential equations (ODE) with a specfic step using the command ode45. The equation has a range between 0 and 2.75 and the intial condition is 1
F=@(R,t)((R/t_a)*((CFS(1,i))/(0.25*taw_0)-R))
[t,R]=ode45(F, [0 2.75], 1)
In this case, Matlab provides a set of values (41 values). For example, t is a set of values range between 0 and 2.75.
How can I specify that I do not want random values of t in the ODE? Here, I want t to range between 0 and 2.75 but I want a step size of 0.25
Thanks,

Risposte (2)

Star Strider
Star Strider il 22 Ott 2022
How can I specify that I do not want random values of t in the ODE? Here, I want t to range between 0 and 2.75 but I want a step size of 0.25
Create ‘tspan’ as a vector of more than two elements.
Specifically —
tspan = 0 : 0.25 : 2.75
tspan = 1×12
0 0.2500 0.5000 0.7500 1.0000 1.2500 1.5000 1.7500 2.0000 2.2500 2.5000 2.7500
Then use that for the ‘tspan’ argument.
The ordinary differential equations integrators will work adaptively as usual, however they will only report results at those times.
.

Torsten
Torsten il 22 Ott 2022
You can't choose the step size of ODE45 because the solver adapts the step size internally. You can only choose the output times by setting the variable "tspan".

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by