Finally, we show how the files in the examples/calculus subdirectory of the
main SAGE_HOME directory can be used. (And please feel free to contribute your
own by emailing them to the Sage Forum or to William Stein.)
In the next example, we will
illustrate Euler's method for
order ODE's.
We first recall the basic idea.
The goal is to find an approximate solution to the problem
Recall from the definition of the derivative that
If we call
Tabular idea:
Let
be an integer, which we call the
step size. This is related to the increment
by
This can be expressed simplest using a table.
| ... | ||
| ... | ||
| ... | ||
| ??? | xxx |
The goal is to fill out all the blanks of the
table but the xxx entry and find the ???
entry, which is the Euler's method
approximation for
.
The idea for systems of ODEs is similar.
Example:
Numerically approximate
at
using
steps of
Euler's method, where
,
,
.
One must reduce the 2nd order ODE down to a system of two
first order DEs (using
,
) and apply Euler's method:
sage: t,x,y = PolynomialRing(RealField(10),3,"txy").gens() sage: f = y; g = -x - y * t sage: eulers_method_2x2(f,g, 0, 1, 0, 1/4, 1) t x h*f(t,x,y) y h*g(t,x,y) 0 1 0.00000 0 -0.25000 1/4 1.0000 -0.062500 -0.25000 -0.23438 1/2 0.93750 -0.11719 -0.46875 -0.17578 3/4 0.82031 -0.15381 -0.61523 -0.089722 1 0.66602 -0.16650 -0.66602 0.00000
Other files useful for illustrating basic aspects of differential equations
os.environ['SAGE_ROOT'] + '/examples/calculus/field_plot2d.sage'.
It has docstrings with many examples of the syntax.
See About this document... for information on suggesting changes.