Eulers Method

Description

eulers_method implements Euler’s method for finding a numerical solution of the first-order ODE $y′=f(x,y)$. The $x$ column of the table increments from $x_0$ to $x_1$ by $h$ (so $(x_1 − x_0)/h$ must be an integer). In the $y$ column, the new $y$-value equals the old $y$-value plus the corresponding entry in the last column. Euler's method is used primarily for pedagogical purposes. The following Sage commands use Euler's method to generate a solution for

(1)
\begin{align} \frac{dy}{dx} & = 5xy - 5 \\ y(0) & = 1, \end{align}

where $h = 1/2$ and $x$ ranges from $0$ to $1$.

Sage Cell

Code

x,y = PolynomialRing(QQ,2,"xy").gens()
eulers_method(5*x+y-5,0,1,1/2,1)

Options

Option

To generate a list of points instead of a table, we can use the following commands.

Code

x,y = PolynomialRing(QQ,2,"xy").gens()
eulers_method(5*x+y-5,0,1,1/2,1,algorithm="none")

Option

We can also generate solutions over the reals.

Code

RR = RealField(sci_not=0, prec=4, rnd='RNDU')
x,y=PolynomialRing(RR,2,"xy").gens()
eulers_method(5*x+y-5,0,1,1/2,1)

Tags

Primary Tags: differential equations

Secondary Tags: numerical methods, euler

A list of possible tags can be found at The WeBWorK Open Problem Library. For linear algebra tags see the Curated Courses Project.

Related Cells

Attribute

Permalink:

Author: Sage Tutorial v8.1

Date: 13 Feb 2018 15:51

Submitted by: Tom Judson

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License