9
$\begingroup$

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]}]
$\endgroup$
1
  • $\begingroup$ @Ghoster, You are right. There is nothing wrong. I misread it. I've edited my question $\endgroup$
    – user444
    Commented Nov 28, 2022 at 6:19

1 Answer 1

12
$\begingroup$
  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[{}, {T*Cos[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

$\endgroup$
5
  • $\begingroup$ Silly me. Thank you for pointing that out $\endgroup$
    – user444
    Commented Nov 28, 2022 at 4:53
  • $\begingroup$ just one more query, Why is that single loop isn't plotting after the Do[...] as shown in book? $\endgroup$
    – user444
    Commented Nov 28, 2022 at 5:01
  • 1
    $\begingroup$ 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]}]] $\endgroup$
    – I.M.
    Commented Nov 28, 2022 at 6:06
  • 1
    $\begingroup$ @user84456 That's a compatibility issue, *Plot functions in and before v5 automatically prints the graphic. See this post for more info: mathematica.stackexchange.com/a/47123/1871 $\endgroup$
    – xzczd
    Commented Nov 28, 2022 at 7:22
  • 1
    $\begingroup$ @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. $\endgroup$
    – xzczd
    Commented Nov 28, 2022 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.