How do I eliminate error when plotting 2D system of DEs with sinusoidal functions?

I'm trying to plot the trajectories of an unforced and undamped pendulum in phase space at various initial conditions. I've got a system defined by:
function dY = undf(t,Y)
th = Y(1);
om = Y(2);
dY(1) = om;
dY(2) = -9.81*sin(th)/0.1;
dY = [dY(1);dY(2)];
end
I'm then using Matlab's ode45 function to calculate om(ega) and th(eta) on a set time interval at a given initial condition. I got good plots for initial conditions (0,0), (0.01,0), and (pi,0). For (pi,0), I used sym(pi) to get rid of round off error. My issue now is that when plotting from the I.C. (3,0), Matlab seems to be rounding off the values of th and om. This gives me a bad plot. I assume this is because sin(3) is an irrational number. However, when I try another I.C., such as (12,0), I get a good plot. Any ideas on how to fix this?
Thanks,
Axel

 Akzeptierte Antwort

Mischa Kim
Mischa Kim am 22 Apr. 2015
Bearbeitet: Mischa Kim am 22 Apr. 2015
Axel, check out odeset. It allows you to set error tolerances. ode45 should work just fine for your problem.
If you show the entire code it is much easier to pinpoint the problem.

1 Kommentar

Thanks for the reply, Mischa. I just tried using odeset to limit RelTol to 1e-10 and it worked. Much appreciated.
-Axel

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by