(I am continuing to use a Jupyter notebook, as in the previous two posts.)
CoCalc (Sage) will solve systems of linear differential equations with constant coefficients exactly. (In fact, it will solve a fairly wide range of differential equations either exactly or numerically.) It can also plot the results.
For example, to solve the system
x'(t) = x+7y
y'(t) = -3x-5y
type:
t = var('t')
x = function('x')(t)
y = function('y')(t)
de1 = diff(x,t) - x -7*y == 0
de2 = diff(y,t) - 3*x - 5*y == 0
desolve_system([de1,de2],[x,y])
Sage will also give you the solution with specific initial values (or “initial conditions”, which it abbreviates “ics”):
sol = desolve_system([de1, de2], [x,y], ics=[0,1,2]); sol
To plot the solution, we’ll use parametric_plot
, which plots parametric curves. Unfortunately, the output of desolve_system
is a “symbolic expression”, while the input to parametric_plot
is a function. Instead of figuring out how to convert between them properly, I’ll use copy-and-paste:
pp = parametric_plot(( 17/10*e^(8*t) - 7/10*e^(-2*t),17/10*e^(8*t) + 3/10*e^(-2*t)),(t,-1.1,0.1)); pp
The differential equation assigns a direction (in our case, (x+7y, 3x+5y)) to each point (x,y) in the plane. This is an example of a vector field. Sage can plot those direction fields, too:
a = var('a')
b = var('b')
vf = plot_vector_field((a+7*b,3*a+5*b),(a,-6,3),(b,0,5)); vf
You can combine the two plots, to see that your trajectory is actually a solution, by adding:
pp + vf