Piecewise functions with ode45 and ode23
9 views (last 30 days)
Show older comments
I have a question pertaining to ode45 and ode23. I am running a simulation of a dynamic mechanical state space system where the input is a bump profile on the ground.
I am trying to get an input profile that has two triangular bumps L apart. I have implemented the system with both ode45 and ode 23.
The input uses the following logic:
if t>0.5 && t<=0.75
db = 1;
elseif t>0.75 && t<1
db = -1;
elseif t>1.5 && t<1.75
db = 1;
elseif t>1.75 && t<=2
db = -1;
else
db = 0;
end
When this is integrated over 3 seconds using ode45 and ode23. When I use ode45 with 3001 points the bump profile comes back to zero with the ground inbetween the bumps being below zero.
When I increase the points to 30001, the bump profile ends up with a ground level below zero.
ode23 seems to integrate the profile as well but still has small errors in the final value. I am wondering why this is happening.
The link below shows the profiles that were created using the various solvers and resolutions: https://docs.google.com/file/d/0B43VsX7mU6SxQ1N1TGRRMTNfbFE/edit
0 Comments
Answers (1)
Jan
on 31 Oct 2012
1. If you checked for t <= 0.75, the following test of t > 0.75 is not useful. Smarter and leaner code:
if t <= 0.5
db = 0;
elseif t<=0.75
db = 1;
elseif t<1
db = -1;
elseif t<1.75
db = 1;
...
2. ODE45 and ODE23 required a continuosly differentiable function for the integration. Otherwise the stepsize control can explode such that the results get random. I do not know, if this solves your problem, but running an integrator outside its specification is a bad idea and not scientifically clean.
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!