Consider the well-known chaotic model of Henon & Heiles (motivated by the motion
ID: 3108698 • Letter: C
Question
Explanation / Answer
File code.m
clear
clc
%% Part (a)
options = odeset('RelTol', 100*eps, 'AbsTol', 1e-14);
[t,y] = ode113(@derivatives, [0 100], [0.24; 0.24; 0.24; 0.24], options);
figure
plot(y(:,1)); hold on
plot(y(:,2)); hold on
plot(y(:,3)); hold on
plot(y(:,4));
legend('p_{1}', 'p_{2}', 'q_{1}', 'q_{2}');
axis([0 1000 -1 1]); xlabel('t');
%% Part (b)
options = odeset(options, 'Events', @q1Events);
[t,y,te,ye,ie] = ode113(@derivatives, [0 2*(10^4)], [0.24; 0.24; 0.24; 0.24], options);
figure, scatter(ye(:,2), ye(:,4));
xlabel('p_{2}'); ylabel('q_{2}');
title('q_{2} vs. p_{2}');
File derivatives.m
function dydt = derivatives(t, y)
dydt = [-y(3)-2*y(3)*y(4);
-y(4)-y(3)*y(3)+y(4)*y(4);
y(1);
y(2)];
end
File q1Events.m
function [position,isterminal,direction] = q1Events(t, y)
position = y(3);
isterminal = 0;
direction = 1;
end
Keep all three files in the same folder and run the file code.m