I have been trying to plot some numeric solutions to a Hamiltonian system. Basically I have :
\[CapitalDelta]t = 10^(-2);
q2[j_] := q2[j] = q2[j - 1] + \[CapitalDelta]t*p2[j - 1];
p2[j_] := p2[j] = p2[j - 1] - \[CapitalDelta]t*Sin[q2[j]];
q2[0] = N@Pi/12;
p2[0] = 0.;
E2[j_] := E2[j] = (p2[j])^2/2 - Cos[q2[j]];
graph2q =
ListPlot[Table[{j*\[CapitalDelta]t, q2[j]}, {j, 0, 1000}],
PlotStyle -> Dashed, AxesLabel -> {"t(s)", "q(t)"}]
graph2p =
ListPlot[Table[{j*\[CapitalDelta]t, p2[j]}, {j, 0, 1000}],
PlotStyle -> Dashed, AxesLabel -> {"t(s)", "p(t)"}]
graph2e =
ListPlot[Table[{j*\[CapitalDelta]t, E2[j]}, {j, 0, 1000}],
PlotStyle -> Dashed, AxesLabel -> {"t(s)", "E(t)"}]
graph2pq =
ListPlot[Table[{q2[j], p2[j]}, {j, 0, 1000}], PlotStyle -> Dashed,
AxesLabel -> {"q(t)", "p(t)"}]
and everything works as expected. However, when I try to change the time interval to 10^-3:
\[CapitalDelta]t = 10^(-3);
q3[j_] := q3[j] = q3[j - 1] + \[CapitalDelta]t*p3[j - 1];
p3[j_] := p3[j] = p3[j - 1] - \[CapitalDelta]t*Sin[q3[j]];
q3[0] = N@Pi/12;
p3[0] = 0.;
E3[j_] := E3[j] = (p3[j])^2/2 - Cos[q3[j]];
graph3q =
ListPlot[Table[{j*\[CapitalDelta]t, q3[j]}, {j, 0, 10000}],
PlotStyle -> Gray, AxesLabel -> {"t(s)", "q(t)"}]
graph3p =
ListPlot[Table[{j*\[CapitalDelta]t, p3[j]}, {j, 0, 10000}],
PlotStyle -> Gray, AxesLabel -> {"t(s)", "p(t)"}]
graph3e =
ListPlot[Table[{j*\[CapitalDelta]t, E3[j]}, {j, 0, 10000}],
PlotStyle -> Gray, AxesLabel -> {"t(s)", "E(t)"}]
graph3pq =
ListPlot[Table[{q3[j], p3[j]}, {j, 0, 10000}], PlotStyle -> Thick,
AxesLabel -> {"q(t)", "p(t)"}]
it gives me the following erros when plotting the E3 function:
>
Whats happening and how can I fix this?