Sage: dynamics of planar systems
## Chapter 6 - exercise 22 (mathematical pendulum)
## attach("nonl-u22.py")
## symbolic variables
var('x y')
## x'=F(x,y), y'=G(x,y)
F = y
G = -sin(x)
## domain of the plot
[x0,x1]=[-4,4]
[y0,y1]=[-2.2,2.2]
## prime integral
v1 = y*y/2 - cos(x) - 1
## plot the levelset {v1=0} (heteroclinic orbit)
V = implicit_plot( v1 , (x,x0,x1), (y,y0,y1), color='blue' ,
linewidth = 1 )
## plot the trajectories (black arrows)
S = streamline_plot( (F,G) , (x,x0,x1), (y,y0,y1), color='black',
density=2 , linewidth=0.3 )
## combine and display the plots (with axes)
P = S + V
P.show(axes=1,aspect_ratio=1,figsize=10)
## optinally, save to a file
#P.save("uloha22.png",axes=1)