License: Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
i.e. the common part of all output files
baseName = "./EOM_1D_explorer_"
xMin = -2
xMax = 2
vMin = -2
vMax = 2
plot_params = dict(xmin = xMin, xmax = xMax, # interval of x-axis
ymin = vMin, ymax = vMax, # y-axis
aspect_ratio=1, # equal scaling of x and y-axis (circles look like circles!)
ticks=(1,1), # ticks with separation of $(\Delta x, \Delta y)$
axes_labels=(r"$x$", # axis labels for x-axis
r"$\dot x$"), # axis label for y-axis
fontsize=16, # size of text font
figsize=(4,4) # figure size
)
plot_params.update( axes_labels = (r"$h$", # axis labels for x-axis
r"$\dot h$") # axis label for y-axis
)
# declare variables
x,v = var("x,v")
# define function
def EOM (x,v) :
return (v, -1-v)
def dGamma_dt(X, t=0):
return [X[1], -1-X[1]]
## solution will be evaluated for times
t = srange(0, 40, 0.01)
## numerical solution of the ODE
from scipy import integrate
def trajectory( IC, **plt_para ) :
TrajectoryPts = integrate.odeint( dGamma_dt, IC, t )
return line( TrajectoryPts, **plt_para )
## plot a single solution
## make + show plot
IC = (1,1)
trajectory( IC, color="blue", thickness=2, **plot_params )
What about
Where is time here?
IC1 = (1,0)
IC2 = (0.55, 1)
plt = trajectory( IC1, color="blue", thickness=2, **plot_params )
plt += trajectory( IC2, color="green", thickness=2, **plot_params )
show(plt)
## plot many solutions
## make + show plot
pt = plot( 0 )
for xIn in srange(xMin-2, xMax, 1) :
pt += trajectory( (xIn, vMax), color="green", thickness=2, **plot_params )
for xIn in srange(xMin, xMax+3, 1) :
pt += trajectory( (xIn, vMin), color="blue", thickness=2, **plot_params )
pt
## add plot parameter for arrow shape and positions
plot_params4ps = dict(
# shaftwidth=3,
headwidth=10,
plot_points=10,
**plot_params )
## make + show plot
pv = plot_vector_field(EOM(x,v), (x,xMin,xMax), (v,vMin,vMax), color="lightgray", **plot_params4ps )
pv
p = pt+pv+plot(-1, (-2,2), thickness=3, color="red")
p
# p.save_image( baseName+"phaseSpace-h.svg" )
# p.save_image( baseName+"phaseSpace-h.pdf" )
p.save_image( baseName+"phaseSpace-h.png", transparent=True)