9

I was following a solved problem from the book mentioned below on the Henon map. However, even after correcting that I still get an error on execution. I am unable to find the exact cause.

Mathematica for Theoretical Physics Classical Mechanics and Nonlinear Dynamics by  Gerd Baumann

Here is the code mentioned in the book.

JacobiMatrix[fun_List, vars_List] := Outer[D, fun, vars]

Clear[HenonMap]

HenonMap[{T_, W_}, α_] := Block[{}, {θCos[2πα] - (W - θ^2) Sin[2πα], θ* Sin[2πα] + (W - θ^2)Cos[2π*α]}]

JacobiMatrix[ HenonMap[{θ, W}, α], {θ, W}] // MatrixForm

JacobiMatrix[HenonMap[{θ, W}, α], {θ, W}] // Det // Simplify

initial = Table[{i, 0, 0}, {i, 0.1, 0.84, 0.015}];

henonPlot = {};

Do[AppendTo[henonPlot, ListPlot[NestList[HenonMap[#, 0.2114] &, initial[[k]], 255], PlotStyle -> Hue[k/Length[initial]], Frame -> True, AspectRatio -> 1, AxesLabel -> {"θ", "W"}, PlotRange -> {{-1, 1}, {-1, 1}}]], {k, 1, Length[initial]}]

xzczd
  • 65,995
  • 9
  • 163
  • 468
user444
  • 2,414
  • 1
  • 7
  • 28

1 Answers1

12
  1. HenonMap[{T_, W_}, α_] uses T in args but θ in body
  2. initial is 3D, should be 2D
JacobiMatrix[fun_List, vars_List] := Outer[D, fun, vars]

Clear[HenonMap]

HenonMap[{T_, W_}, α_] := Block[{}, {TCos[2πα] - (W - T^2) Sin[2πα], T* Sin[2πα] + (W - T^2)Cos[2π*α]}]

JacobiMatrix[ HenonMap[{θ, W}, α], {θ, W}] // MatrixForm

JacobiMatrix[HenonMap[{θ, W}, α], {θ, W}] // Det // Simplify

initial = Table[{i, 0}, {i, 0.1, 0.84, 0.015}];

henonPlot = {};

Do[AppendTo[henonPlot, ListPlot[NestList[HenonMap[#, 0.2114] &, initial[[k]], 255], PlotStyle -> Hue[k/Length[initial]], Frame -> True, AspectRatio -> 1, AxesLabel -> {"θ", "W"}, PlotRange -> {{-1, 1}, {-1, 1}}]], {k, 1, Length[initial]}]

Show[henonPlot]

enter image description here

xzczd
  • 65,995
  • 9
  • 163
  • 468
I.M.
  • 2,926
  • 1
  • 13
  • 18
  • Silly me. Thank you for pointing that out – user444 Nov 28 '22 at 04:53
  • just one more query, Why is that single loop isn't plotting after the Do[...] as shown in book? – user444 Nov 28 '22 at 05:01
  • 1
    Do doesn't not return values, in this code plots are appended to a list, you need to use Show to combine them and show. Using Table is more in WM style Show[Table[ListPlot[ ...], {k, 1, Length[initial]}]] – I.M. Nov 28 '22 at 06:06
  • 1
    @user84456 That's a compatibility issue, *Plot functions in and before v5 automatically prints the graphic. See this post for more info: https://mathematica.stackexchange.com/a/47123/1871 – xzczd Nov 28 '22 at 07:22
  • 1
    @user84456 Which version of Baumann's book are you using? I just checked version 2 of the book, definitions of HenonMap and initial are both correct therein. – xzczd Nov 28 '22 at 07:34