Strange problem with tspan in ode45

30 visualizaciones (últimos 30 días)
VD
VD el 8 de Abr. de 2020
Comentada: Ameer Hamza el 9 de Abr. de 2020
Hi all,
I'm currently trying to solve an ODE with ode45. I'm having trouble with the solution I find. It seems that by using as tspan = [0 100] instead than linspace(0,100,100) (for example) in the ode45 inputs, the solution I get changes. I know that these two options are not exactly the same, but I've tried to study the MATLAB documentation related to this issue, and I do not find anything convincent enough. Any clue? Which solution is more accurate?
Below you can find two plots; for different initial conditions. The first column is the solution using tspan = [0 100] and the second column is with the linspace option.
It clearly seems that the option of using tspan = [0 100] is more accurate, but I do not really understand why.
Thanks in advance!!

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 8 de Abr. de 2020
Editada: Ameer Hamza el 8 de Abr. de 2020
This issue is not about accuracy. When you use tspan=[0 100], the t vector returned by ode45 is adaptively spaced. The differences between consecutive t values are not always constant. Note that the returned t vector can have any length, and MATLAB will smartly create vector t such that it captures the variation in your output signal. Now, when you use
t = linspace(0,100,100)
The ode45 still internally solves the equation exactly the same as before, but now it will the value of output signal at the time vector you provided. You can see that elements of linspace(0,100,100) are equally spaced and have no sense of where the function has variations and where it is smooth. To see the difference, just increase the number of elements in vector t
t = linspace(0,100,1000)
and you will see that it approach the output given by ode45.
  2 comentarios
VD
VD el 9 de Abr. de 2020
Hi,
That was the answer I was looking for. Thanks!
Ameer Hamza
Ameer Hamza el 9 de Abr. de 2020
Glad to be of help.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by