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:
BinCounts::step: The bin step size -6.26618*10^-6 is expected to be positive. >>
Mean::rectt: Rectangular array expected at position 1 in Mean[0.00009999]. >>
Part::pkspec1: The expression Which[(0.00009999 BinCounts[{{0.,-0.965926},{0.001,-0.965926},{0.002,-0.965926},<<46>>,{0.049,-0.965924},<<9951>>},<<1>>,{<<1>>}])/Mean[0.00009999]<2,1,Charting`CommonDump`density>10,2,True,3] cannot be used as a part specification. >>
Part::pkspec1: The expression Which[(0.00009999 BinCounts[{{0.,-0.965926},{0.001,-0.965926},{0.002,-0.965926},<<46>>,{0.049,-0.965924},<<9951>>},<<1>>,{<<1>>}])/Mean[0.00009999]<2,1,Charting`CommonDump`density>10,2,True,3] cannot be used as a part specification. >>
Whats happening and how can I fix this?