[Go to the Notes on Diffy Qs home page]

Notes on Diffy Qs - Sage demos for section 3.1

Press the Evaluate button below to launch the Sage demonstration.

Solving systems of ODE

Similarly to how you can ask Sage to solve one ODE, you can ask it to solve a system. Here we solve the system \(x' =x-y, y'=x+y+t.\) Note that the solver only succeeds in cases when Sage can find an analytic solution, otherwise you get an error.

We could also put in some initial equations. Here, the vector given as "ics" represents the initial t, initial x, and initial y. So for example, to solve for the initial conditions \(x(0)=1,y(0)=2\) you use "[0,1,2]".

Plotting vector fields for autonomous system of ODE

If we have an autonomous system of two ODE we can plot the vector field in the following way. Here we plot \(x' = x\sin(\pi y), y'=x-y.\)

We may also want to plot a trajectory. Here we numerically solve the ODE system for initial condition \(x=1.0\) and \(y=-1.5\) for \(t\) in the range from 0 to 10. You can also get more of an idea of how fast the solution is moving by setting plotjoined to False below, which will simply plot a point at each step of the numerical solution (we are using Runge-Kutta).


Valid HTML 5 Valid CSS!