Applying Euler's Method to Differential Equations

Instructor: Gerald Lemay

Gerald has taught engineering, math and science and has a doctorate in electrical engineering.

Having a method for solving differential equations when the standard analytic techniques don't work is a great thing. In this lesson, we'll explore one of the most intuitive numerical approaches for finding a solution to a differential equation: Euler's method.

Differential Equations

At sometime in your life, you might find yourself solving a differential equation. It might be on the job as a scientist or an engineer, or while working on a homework problem.

A differential equation is one with derivatives in it, or the points on a graph where a function changes. We solve a differential equation by finding all the x and y values that make the equation true; plotting these points on an x-y graph leads to a curve, or the solution.

Sometimes we can identify the function for the curve, which is called the analytic solution. On other occasions, the analytic solution is difficult or impossible to find. In these cases, we can use a numerical method to find some points on or close to the curve. In this lesson, we'll explore the numerical method called Euler's method.

Recipe for Euler's Method

When solving a differential equation, we need a place to start, or an initial condition: the value of y we call yo when x equals xo.


Initial condition or starting point
Having_a_place_to_start_is_essential


Now we need a direction for the next point. Enter calculus!


The derivative points in the right direction.
null


Imagine moving along the tangent line as xo takes a step to x1. The tangent line is one that meets but does not cross a curve at a certain point.


The tangent line meets the curve.
Taking_the_next_step_is_easy


The slope of this line is the change in y divided by the change in x. The change in y is y1 - yo, and the change in x is x1 - xo.

The slope at xo is the derivative of y with respect to x, written as dy/dx. Thus,


 dy/dy=(y1-y0)/(x1-x0)


To streamline things, replace x1 - xo with h:


dy/dx=(y1-y0)/h


Using some algebra, solve for y1:


y1=yo+h(dy/dx)


Here's what the differential equation looks like in this example:


y_prime=4x


This example has an analytic solution:


y=2x^2+2


Let's check the analytic solution:

  • Identify the initial condition (y at x = 0): 2.
  • Substitute x = 0 in the solution (y = 2x2 + 2): y = 2(0) + 2 = 2.
  • The analytic solution makes the differential equation true.
  • Differentiate y = 2x2 + 2 with respect to x: 4x + 0 = 4x.
  • The differential equation is y ' = 4x.

This example provides us with an analytic solution to compare with Euler's method. Typically, we use a numerical method when the analytic solution does not exist.

Here's our equation for y1:


y1=yo+h(dy/dx)


Let's relate this equation to our differential equation:


y_prime=4x


Do you recognize the y prime on the left-hand side as the dy/dx in our y1 equation?

On the right-hand side, we also have a function of x and y, which we write as f(x, y). In our example, f(x, y) is simply 4x.

Do you agree dy/dx equals f(x, y)? Our differential equation is y ' = 4x. On the left-hand side, y ' is the same as dy/dx. On the right-hand side, 4x is f(x, y). Thus, dy/dx = f(x, y).

Our next step in developing Euler's method is to write:


y1=yo+hf(x,y)


See how we replaced dy/dx with f(x, y)?

At x = xo, y = yo. Thus, f(x, y) can be evaluated at this point:


y1=yo+h(f(xo,yo)


On the right-hand side, the subscripts are zero. But on the left-hand side, the subscript is 1.

Usually, if the subscript on the right-hand side is n, the subscript on the left-hand side is n + 1:


y_(n+1)=y_n+hf(x_n,y_n)


This last equation is the recipe for Euler's method. The next value of y is based on the current value of y, the step size h (or change in x), and the function evaluated at the current x and y values. Let's see how Euler solves the differential equation in our example.

Application of Euler's Method

Solve the differential equation: y ' = 4x on the interval x = 1 to x = 3, given y(1) = 4.

Step 1: Select a Step Size (h)

Let's start with a step size of h = 0.5.

Step 2: Create a Table

To keep track of the computations, we'll use a 5-table column, where each column is devoted to the values found in the Euler 'recipe.'

n xn yn f(xn, yn) h f(xn, yn)

Step 3: Enter the n and xn Values

n xn yn f(xn, yn) h f(xn, yn)
0 1.0 4
1 1.5
2 2.0
3 2.5
4 3.0

The first value for x is 1.0. This is our xo. In steps of h = 0.5, the next values of x are 1.5, 2.0, 2.5, and 3.0. The n values start at 0 and end at n = 4. We'll also enter the starting point: y = 4 when x = 1.0.

Step 4: Calculate and Plot

Here, f(x, y) = 4x. So, f(xo, yo) is 4(xo) = 4(1) = 4.

To unlock this lesson you must be a Study.com Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use Study.com

Become a Study.com member and start learning now.
Become a Member  Back
What teachers are saying about Study.com
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? Study.com has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account
Support