\(\(\( (*\ 
      planar\ pendulum\ with\ initial\ condition\ x = 
        0
	\((x\ stands\ for\ the\ angle\ theta\ in\ the\ notes)\), \ 
      p = \(pin = YOUR\ CHOICE\)\ , \ below\ I\ picked\ 1\ , \ 
      you\ can\ try\ other\ values, \ 
      the\ 
		separation\ is\ at\ pin = 2\ ; 	

      You\ can\ also\ adjust\ tmax\ the\ time\ you\ run\ the\ ODE*) \)\(
\)\(\(pin = 1\)\(;\)\(tmax = 20\)\(;\)\(
\)\(
\)\(
\)\( (*\ 
      building\ the\ vector\ field\ \((v, w)\)\ *) \)\)\)\)

h[x_, p_] := (1/2)*(p^2) + g*(1 - Cos[x]);
g = 1;
v[t_] := D[h[x, p], p] /. {x -> x[t], p -> p[t]};
w[t_] := -D[h[x, p], x] /. {x -> x[t], p -> p[t]};
{v[t], w[t]}

\(\(\( (*\ 
      Integrating\ the\ differential\ equation\ *) \)\(
\)\(\(acgoal = 
        10;\)

    \(precgoal = 16;\)

    \(aa = 
        NDSolve[{\(x'\)[t] == v[t], \(p'\)[t] == w[t], x[0] == 0, 
            p[0] == pin}, {x, p}, 
	{t, 0, tmax}, MaxSteps -> 10000, 
	
          AccuracyGoal -> acgoal, PrecisionGoal -> precgoal];\)

    fig = 
      ParametricPlot[{\((x[t] /. aa)\)[\([1]\)], \((p[t] /. 
                aa)\)[\([1]\)]}, {t, 0, tmax}, PlotPoints -> 2000, 
        AxesLabel -> {x, p}, PlotRange -> All]


    \)\)\)

llmax = 10;
\(\(Do[pin = 0.1*ll; 
        aa = NDSolve[{\(x'\)[t] == v[t], \(p'\)[t] == w[t], x[0] == 0, 
              p[0] == pin}, {x, p}, 
	{t, 0, tmax}, MaxSteps -> 10000, 
	
            AccuracyGoal -> acgoal, PrecisionGoal -> precgoal]; 

        figu[ll] = 
          ParametricPlot[{\((x[t] /. aa)\)[\([1]\)], \((p[t] /. 
                    aa)\)[\([1]\)]}, {t, 0, tmax}, PlotPoints -> 2000, 
            AxesLabel -> {x, p}, PlotRange -> All, 
            DisplayFunction -> Identity], {ll, 1, 
          llmax}];\)\)
Show[Table[figu[ll], {ll, 1, llmax}], 
      DisplayFunction -> $DisplayFunction]

tmax = 6; llmax = 10;
\(\(Do[pin = 0.2*ll; 
        aa = NDSolve[{\(x'\)[t] == v[t], \(p'\)[t] == w[t], x[0] == 0, 
              p[0] == pin}, {x, p}, 
	{t, 0, tmax}, MaxSteps -> 10000, 
	
            AccuracyGoal -> acgoal, PrecisionGoal -> precgoal]; 

        figu[ll] = 
          ParametricPlot[{\((x[t] /. aa)\)[\([1]\)], \((p[t] /. 
                    aa)\)[\([1]\)]}, {t, 0, tmax}, PlotPoints -> 2000, 
            AxesLabel -> {x, p}, PlotRange -> All, 
            DisplayFunction -> Identity], {ll, 1, llmax}];\)\)
Show[Table[figu[ll], {ll, 1, llmax}], 
      DisplayFunction -> $DisplayFunction]

tmax = 15; llmax = 15;
\(\(Do[pin = 0.2*ll; 
        aa = NDSolve[{\(x'\)[t] == v[t], \(p'\)[t] == w[t], x[0] == 0, 
              p[0] == pin}, {x, p}, 
	{t, 0, tmax}, MaxSteps -> 10000, 
	
            AccuracyGoal -> acgoal, PrecisionGoal -> precgoal]; 

        figu[ll] = 
          ParametricPlot[{\((x[t] /. aa)\)[\([1]\)], \((p[t] /. 
                    aa)\)[\([1]\)]}, {t, 0, tmax}, PlotPoints -> 2000, 
            AxesLabel -> {x, p}, PlotRange -> All, 
            DisplayFunction -> Identity], {ll, 1, llmax}];\)\)
Show[Table[figu[ll], {ll, 1, llmax}], 
      DisplayFunction -> $DisplayFunction]

tmax = 15; llmax = 10;
\(\(Do[pin = 0.3*ll; 
        aa = NDSolve[{\(x'\)[t] == v[t], \(p'\)[t] == w[t], x[0] == 0, 
              p[0] == pin}, {x, p}, 
	{t, 0, tmax}, MaxSteps -> 10000, 
	
            AccuracyGoal -> acgoal, PrecisionGoal -> precgoal]; 

        figu[ll] = 
          ParametricPlot[{Mod[\((x[t] /. aa)\)[\([1]\)], 
                2*Pi], \((p[t] /. aa)\)[\([1]\)]}, {t, 0, tmax}, 
            PlotPoints -> 2000, AxesLabel -> {x, p}, PlotRange -> All, 
            DisplayFunction -> Identity], {ll, 1, llmax}];\)\)
Show[Table[figu[ll], {ll, 1, llmax}], 
      DisplayFunction -> $DisplayFunction]

tmax = 15; llmax = 16;
\(\(Do[pin = 1 + 0.1*ll; 
        aa = NDSolve[{\(x'\)[t] == v[t], \(p'\)[t] == w[t], x[0] == 0, 
              p[0] == pin}, {x, p}, 
	{t, 0, tmax}, MaxSteps -> 10000, 
	
            AccuracyGoal -> acgoal, PrecisionGoal -> precgoal]; 

        figu[ll] = 
          ParametricPlot[{Mod[\((x[t] /. aa)\)[\([1]\)], 
                2*Pi], \((p[t] /. aa)\)[\([1]\)]}, {t, 0, tmax}, 
            PlotPoints -> 2000, AxesLabel -> {x, p}, PlotRange -> All, 
            DisplayFunction -> Identity], {ll, 1, llmax}];\)\)
Show[Table[figu[ll], {ll, 1, llmax}], 
      DisplayFunction -> $DisplayFunction]

Integrate[(1 + Cos[th])^(-1/2), {th, 0, th1}]

Plot[
      Integrate[(1 + Cos[th])^(-1/2), {th, 0, th1}], {th1, 0.1, 
        3.14}]

\(\(\( (*\ 
      Integrating\ the\ differential\ equation\ *) \)\(
\)\(\(acgoal = 
        10;\)

    precgoal = 16; tmax = 100; pin = 1;

    \(aa = 
        NDSolve[{\(x'\)[t] == v[t], \(p'\)[t] == w[t], x[0] == 0, 
            p[0] == pin}, {x, p}, 
	{t, 0, tmax}, MaxSteps -> 10000, 
	
          AccuracyGoal -> acgoal, PrecisionGoal -> precgoal];\)

    fig = 
      ParametricPlot[{\((x[t] /. aa)\)[\([1]\)], \((p[t] /. 
                aa)\)[\([1]\)]}, {t, 0, tmax}, PlotPoints -> 2000, 
        AxesLabel -> {x, p}, PlotRange -> All]

    \)\)\)

\(\(\(Plot[\((x[t] /. aa)\)[\([1]\)], {t, 0, tmax}]\)\(
\)
    \)\)

Plot[((h[x[t], p[t]] /. aa) - 
            1/2)*10^7, {t, 0, tmax}]

\(\(\( (*\ 
      Integrating\ the\ differential\ equation\ *) \)\(
\)\(\(acgoal = 4;\)

    
    precgoal = 8; tmax = 100; pin = 1;

    \(aa = 
        NDSolve[{\(x'\)[t] == v[t], \(p'\)[t] == w[t], x[0] == 0, 
            p[0] == pin}, {x, p}, 
	{t, 0, tmax}, MaxSteps -> 10000, 
	
          AccuracyGoal -> acgoal, PrecisionGoal -> precgoal];\)

    fig = 
      ParametricPlot[{\((x[t] /. aa)\)[\([1]\)], \((p[t] /. 
                aa)\)[\([1]\)]}, {t, 0, tmax}, PlotPoints -> 2000, 
        AxesLabel -> {x, p}, PlotRange -> All]; 
    Plot[\((\((h[x[t], p[t]] /. aa)\) - 1/2)\), {t, 0, 
        tmax}]

    \)\)\)