Tutorial Release 10.4 The Sage Development Team https://doc.sagemath.org/pdf/en/tutorial/sage_tutorial.pdf
Sage is free, open-source math software that supports research and teaching in algebra, geometry, number theory, cryptography, numerical computation, and related areas. Both the Sage development model and the technology in Sage itself are distinguished by an extremely strong emphasis on openness, community, cooperation, and collaboration: we are building the car, not reinventing the wheel. The overall goal of Sage is to create a viable, free, open-source alternative to Maple, Mathematica, Magma, and MATLAB.
This tutorial is the best way to become familiar with Sage in only a few hours. You can read it in HTML or PDF versions, or from the Sage notebook (click Help, then click Tutorial to interactively work through the tutorial from within Sage).
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
ubuntu2204
2.4.4 Euler’s Method for Systems of Differential Equations
In the next example, we will illustrate Euler’s method for first and second order ODEs. We first recall the basic idea for first order equations. Given an initial value problem of the form
we want to find the approximate value of the solution at ( x = b ) with ( b > a ). Recall from the definition of the derivative that
where ( h > 0 ) is given and small. This and the DE together give
Now solve for ( y(x + h) ):
If we call ( h \cdot f(x, y(x)) ) the “correction term” (for lack of anything better), call ( y(x) ) the “old value of ( y )”, and call ( y(x+h) ) the “new value of ( y )”, then this approximation can be re-expressed as
If we break the interval from ( a ) to ( b ) into ( n ) steps, so that ( h = \frac{b-a}{n} ), then we can record the information for this method in a table.
The goal is to fill out all the blanks of the table, one row at a time, until we reach the ??? entry, which is the Euler’s method approximation for ( y(b) ).
The idea for systems of ODEs is similar.
Numerical Approximation via Euler's Method
In this example, we will numerically approximate ( z(1) ) using 4 steps of Euler's method. Consider the differential equation:
with initial conditions , ).
Reducing the Second Order ODE
To apply Euler's method, we first reduce the second order ODE to a system of first order ODEs. Let ( x = z ) and ( y = z' ), leading to:
Code Implementation
The table output indicates .
Plotting the Approximation
We can visualize this approximation by plotting the points ().
At this point, ( P ) stores two plots: ( P[0] ), the plot of ( x ) vs. ( t ), and ( P[1] ), the plot of ( y ) vs. ( t ).
This visual representation helps in understanding the dynamics of the system for the given interval.
(For more on plotting, see Plotting.)