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

조회 수: 2 (최근 30일)
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

채택된 답변

Mischa Kim
Mischa Kim 2015년 4월 22일
편집: Mischa Kim 2015년 4월 22일
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
Axel Larsson
Axel Larsson 2015년 4월 22일
Thanks for the reply, Mischa. I just tried using odeset to limit RelTol to 1e-10 and it worked. Much appreciated.
-Axel

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by