In this section, we provide a few details which are useful to teaching a lower level ordinary differential equations course using Sage.
The displacement from equilibrium (respectively) for a coupled spring attached to a wall on the left
|------\/\/\/\/\---|mass1|----\/\/\/\/\/----|mass2|
spring1 spring2
where
Example:
Use Sage to solve the above problem with
,
,
,
,
,
,
,
.
Solution: Take the Laplace transform of the first DE (for simplicity of notation, let
,
):
sage: de1 = maxima("2*diff(x(t),t, 2) + 6*x(t) - 2*y(t)")
sage: lde1 = de1.laplace("t","s"); lde1
2*(-?%at('diff(x(t),t,1),t=0)+s^2*?%laplace(x(t),t,s)-x(0)*s)-2*?%laplace(y(t),t,s)+6*?%laplace(x(t),t,s)
sage: de2 = maxima("diff(y(t),t, 2) + 2*y(t) - 2*x(t)")
sage: lde2 = de2.laplace("t","s"); lde2
-?%at('diff(y(t),t,1),t=0)+s^2*?%laplace(y(t),t,s)+2*?%laplace(y(t),t,s)-2*?%laplace(x(t),t,s)-y(0)*s
sage: var('s X Y')
(s, X, Y)
sage: eqns = [(2*s^2+6)*X-2*Y == 6*s, -2*X +(s^2+2)*Y == 3*s]
sage: solve(eqns, X,Y)
[[X == (3*s^3 + 9*s)/(s^4 + 5*s^2 + 4),
Y == (3*s^3 + 15*s)/(s^4 + 5*s^2 + 4)]]
sage: var('s t')
(s, t)
sage: inverse_laplace((3*s^3 + 9*s)/(s^4 + 5*s^2 + 4),s,t)
cos(2*t) + 2*cos(t)
sage: inverse_laplace((3*s^3 + 15*s)/(s^4 + 5*s^2 + 4),s,t)
4*cos(t) - cos(2*t)
...)
sage: t = var('t')
sage: P = parametric_plot( (cos(2*t) + 2*cos(t), 4*cos(t) - cos(2*t) ),\
... 0, 2*pi, rgbcolor=hue(0.6) )
show(P) to view this). The individual components
can be plotted using
sage: t = var('t')
sage: Px = plot( cos(2*t) + 2*cos(t) , 0, 2*pi, rgbcolor=hue(0.6) )
sage: Py = plot( 4*cos(t) - cos(2*t) , 0, 2*pi, rgbcolor=hue(0.6) )
For an interactive ``zoomable'' plot, try (do not type the ...)
sage: maxima.plot2d('cos(2*x) + 2*cos(x)','[x,0,1]',\
... '[plot_format,openmath]') # not tested
REFERENCES: Nagle, Saff, Snider, Fundamentals of DEs, 6th ed, Addison-Wesley, 2004. (see §5.5).
See About this document... for information on suggesting changes.