MATLAB: 1D ODE depending on a parameter: how to have exact same length solutions for every parameter to make a 3d plot of them

3d plotsmeshodeode45refine solutions

I have to solve a 1D ODE depending on a parameter r and compare the solutions for different values of the parameter. In particular I want to make a 3d plot with the parameter r and the time t as (x,y) and the solution g(r,t) as z. I am solving the ode with ode45 but for different values of r the solver needs more and more steps, as in fact for r larger than a critical value my solution always explodes for mathematical reasons. Hence I have vectors of different size for every r.
How can I force ode45 to use an exact same number of steps?
Or how can I refine solution that I have to achieve the same size?
Or how can I make such a 3d plot with y,z vectors all of different size for every x?
Thank you

Best Answer

  • If you define tspan with more than 2 elements, the trajectories are exported for the given times only.