Вы находитесь на странице: 1из 17

1.

Introduction

Eulers Method
There are some differential equations where this technique will not
work. There are other techniques for solving differential equations, but
again they too sometimes fail. This is where Euler's Method is used.
Euler's Method provides us with an approximation for the solution of a
differential equation. The idea behind Euler's Method is to use the concept
of local linearity to join multiple small line segments so that they make up
an approximation of the actual curve.

The first derivative provides a

direct estimate and refers to Eulers method which is:


y n+1= y n+ f ( x n , y n ) h
2

Differential equations can describe nearly all systems undergone change.

They are ubiquitous in science and engineering as well as economics,


social science, biology, business, etc. Many mathematicians have studied
the nature of these equations and many complicated systems can be
described

quite

precisely

with

compact

mathematical

expressions.

However, many systems involving differential equations are so complex or


the systems that they describe are so large that a purely analytical
solution to the equation is not tractable.
It is in these complex systems where computer simulations and
numerical

approximations

are

useful.

The

techniques

for

solving

differential equations based on numerical approximations were developed


before programmable computers existed. The problem of solving ordinary
differential equations is classified into two namely initial value problems
and boundary value problems, depending on the conditions at the end
points of the domain are specified. All the conditions of initial value
problem are specified at the initial point. There are numerous methods
1 Numerical Methods for Engineers, fifth edition, page 682
2 The Pacific Journal of Science and Technology : Eulers Method for Solving Initial
Value Problems in Ordinary Differential Equations. By Sunday Fadugba. Page 1
1

that produce numerical approximations to solution of initial value problem


in ordinary differential equation such as Eulers method which was the
oldest and simplest such method originated by Leonhard Euler in 1768,
Improved Euler method, Runge Kutta methods described by Carl Runge
and Martin Kutta in 1895 and 1905, respectively.
2.0 Theory
Theoretical Introduction
Eulers method is also called tangent line method and is the simplest

numerical method for solving initial value problem in ordinary differential


equation,

particularly

suitable

for

quick

programming

which

was

originated by Leonhard Euler in 1768. This method subdivided into three


namely:
1. Forward Eulers method.
2. Improved Eulers method.
3. Backward Eulers method.
Solving differential equations numerically meant coding the method into
the computer yourself. Today there are numerous solvers available that
can handle the majority of classes of initial value problems with little user
intervention

other

than

entering

the

actual

problem.

However,

occasionally it still becomes necessary to do some customize coding in


order to attack a problem that the prewritten solvers can't quite handle.

Deriving the Euler's Method Formulas

For example solving the initial value problem below:


3 The Pacific Journal of Science and Technology : Eulers Method for Solving Initial
Value Problems in Ordinary Differential Equations. By Sunday Fadugba. Page 1
2

y '=f ( x , y )

y (x 0)= y 0

Let's use the names:

(x n , y n )

x
( n+1 , y n+1 )

for the known point

for the new point

Clearly it lies on the 4tangent line, and this tangent line has a known
slope, namely

f (xn , y n) . Let's mark on our picture names for the sizes of

the x-jump, and the y-jump as we move from the known point,

( x n , y n ) , to

the new point. Let's also write in the slope of the tangent line that we just
mentioned. Doing so, we get:

4 The Pacific Journal of Science and Technology : Eulers Method for Solving Initial
Value Problems in Ordinary Differential Equations. By Sunday Fadugba. Page 3
3

The formula relating

xn

and

x n+1

x n+1

is obvious:

x n+ h

Also, we know from basic algebra that slopes = rise / run, so applying this
idea to the triangle in our picture, the formula becomes:
f (xn , y n)=y /h

which can be rearranged to solve for

y giving us:

y =h f ( xn , y n)

But, we're really after a formula for

y n+1

. Looking at the picture, it's

obvious that:
y n+1= y n+ y

And, replacing

by our new formula, this becomes:


y n+1= y n+ h f ( x n , y n)

Formula required generating a numerical solution to an initial value


problem using Euler's Method.
3.0 Algorithm
Solve the differential equation

dy /dx=( yx )/ y+ x

at

x=0.1 , using

Eulers method in five steps. Given y(0) = 1

Start
if (count < n) then
y = y + h * f( x,y)
x=x+h
write
x,ythe initial
Enter
Enter
number
of
Enterthe
the
value+at
count
=
count
1
values;
x,y
steps required,
which
result
isnto
= (a-x)/n
Gotoh the
step
7
Stop
write
x ,y
found,
Endifbe
count
= 1a

4.0 Advantages and Disadvantages


Eulers method is the most elementary approximation technique for
solving initial-value problems. Although it is seldom used in practice, the
simplicity of its derivation can be used to illustrate the techniques
involved in the construction of some of the more advanced techniques,
without the cumbersome algebra that accompanies these constructions.
5

The principal advantage of the Euler method is that simple to


understand, and relatively easy to execute either by hand or via computer
program.
However, the disadvantages Euler method is limited by its linear
nature. A very small step sizes, h are need to keep significant error from
propagating. Besides, for more complicated equation, or find the solution
over a lager of x, the inherent error in Euler method, coupled with the
increasingly small steps size requires significant computer time and
power5. Although Eulers method is not accurate enough to warrant its use
in practice, it is sufficiently elementary to analyze the error that is
produced from its application. The error analysis for the more accurate
methods is consider in subsequent sections follows the same pattern but
is more complicated. The truncation errors are composed of two parts. The
first is a local truncation error that results from an application of the
method in question over a single step 6. The second is a propagated
truncation error that results from the approximations produced during the
previous steps. The sum of the two is the total or global truncation error.

5.0 Example without MATLAB


A rectifier-based power supply requires a capacitor to temporarily store
power when the rectified waveform from the AC source drops below the
target voltage. To properly size this capacitor, a first-order ordinary
5 Richard L. Burden, J.Dougles Faires, Numerical Analysis, 9 th edition,Page 266.
6 Chapra Steven C, canale Raymond P, numberical methods foe engineers, 6 th
edition,Page 713.
6

differential equation must be solved. For a particular power supply, with a


capacitor of, the ordinary differential equation to be solved is

|18 cos ( 120 ( t ) )|2v(t)


dv (t)
1
=
0.1+max
,0
6
dt
0.04
150 x 10

))

v 0 =0

Where,

Using Eulers method, find the voltage across the capacitor at t=0.00004s.
Step size, h=0.00002s.
Solution:

|18 cos ( 120 ( t ) )|2v


dv
1
=
0.1+max
,0
6
dt 150 x 10
0.04

f (t , v )=

))

|18 cos ( 120 ( t ) )|2v


1
0.1+
max
,0
0.04
150 x 106

))

The Eulers method formula

V i+1=V i+ f ( t i , V i ) h

Where

i=0 ;

t 0=0
V 0=0

Thus,
V 1 V 0 + f ( t0 , V 0 ) h
V 1=0+ f ( 0,0 ) 0.00002

0+

))

|18 cos ( 120 (t ) )|20


1
0.1+ max
, 0 0.00002
6
0.04
150 x 10

0+ ( 2.666 x 10 6 ) 0.00002
53.320V

The approximate value of

V1

= 53.320V

At,
t=t 1 =t 0 + h=0+ 0.00002=0.00002 sec

Thus, the approximate voltage for

t1

= 0.00002 is:

V ( 0.00002 ) V 1=53.320 V

Where

i=1 ;

t 1 =0.00002
V 1=53.320
V 2=V 1 + f ( t 1 V 1) h
Recall,

f (t 1 , V 1)=

))

|18 cos ( 120 ( t ) )|2V 1


1
0.1+max
,0
0.04
150 x 106

|18 cos ( 120 ( t ) )|253.320


1
0.1+ max
,0
6
0.04
150 x 10

f (0.00002, 53.320)=

1
(0.1+max (933.01 , 0 ) )
150 x 106

))

f (0.00002, 53.320)=

1
(0.1+ 0 )
150 x 106

666.6667
Recall Eulers formula
V 2=V 1 + f ( t 1 V 1) h
V 2=53.320+ (666.6667 ) 0.00002
V 2=53.3066 V

The approximate value of

V2

= 53.3066V

At,
t=t 2=t 1 +h=0.00002+0.00002=0.00004 sec

The approximate voltage for

= 0.00004 is:

V ( 0.00002 ) V 2=53.3066 V

6.0 Example with MATLAB


A) For coding source, see at appendix.
B) Result

10

Graph 1: Exact and approximate solution of the ODE by Euler Method.

7.0 The Comparison between MATLAB and Without MATLAB


The First, to compare between this two method either manually or
computerized refer to table 1 and graph 1. By looking at the Step size, h =
0.00002, we can find the approximation of the solution with wider step but
the error is too large even though the computation by hand captured the
general trend of the true solution (the green line shows the solution with
wider step, h). This also known as Truncation errors caused by the nature
of the techniques employed to approximate value of y. Of course by using
smaller value, h, will guarantee the accuracy of the approximation but this
is almost impossible to do it by hand because the computation is too
many to calculate manually (coordination or point by point increases).
When we move on to using the computer to do the work, we needn't be so
afraid of using tiny step-sizes. Using MATLAB, it is possible to use much
smaller step in order for the approximation to become much more
accurate the only disadvantage of computation by computer is the roundoff errors caused by the limited number of significant digits that can be
retained by a computer.

Step size, h

v 0.00004

Exact value

Et

|t | %

0.00002

53.3067

15.9741

-37.3326

233.707
11

0.000002
0.0000002
0.00000002
0.000000002

8.88666
1.04863
0.106462
0.0106622

7.78338
1.03163
0.106285
0.0106604

-1.10329
-0.0169964
-0.000176945
-0.000001776

14.1749
1.64753
0.166481
0.0166648

Table 1: value of voltage at t=0.00004 with different step size.

8.0 Conclusion
From this assignment, it noticed that the introduction of Eulers
method, advantages and disadvantages of Eulers method, comparison of
solving Euler method with and without MATLAB, and also the Eulers
method algorithm. Eulers Method is a form of numerical integration a
way to approximate the solution of a first-order differential equation where
the initial point in the solution curve is known, but the shape of the curve
is unknown. Euler method frequently used the logarithm function as a tool
in analysis problems, and discovered new ways by which they could be
used. Its discovered ways to express various logarithmic functions in
terms of power series, and successfully defined logarithms for complex
and negative numbers, thus

greatly expanding the

scope

where

logarithms could be applied in mathematics. Eulers method is the most


elementary approximation technique for solving initial-value problems.
The principal advantage of the Euler method is that simple to understand,
and relatively easy to execute either by hand or via computer program.
However, the disadvantages Euler method is limited by its linear
nature. A very small step sizes, h are need to keep significant error from
propagating. Besides, for more complicated equation, or find the solution
12

over a larger of x, the inherent error in Euler method, coupled with the
increasingly small steps size requires significant computer time and
power. Although Eulers method is not accurate enough to warrant its use
in practice, it is sufficiently elementary to analyze the error that is
produced from its application. The error analysis for the more accurate
methods is consider in subsequent sections follows the same pattern but
is more complicated. The truncation errors are composed of two parts. The
first is a local truncation error that results from an application of the
method in question over a single step. The second is a propagated
truncation error that results from the approximations produced during the
previous steps. The sum of the two is the total or global truncation error.

9.0 Reference
1. Richard L. Burden, J.Dougles Faires, Numerical Analysis, 9th edition.
2. Chapra Steven C, canale Raymond P, numberical methods foe
engineers, 6th edition.
3. The Pacific Journal of Science and Technology: Eulers Method for
Solving Initial Value Problems in Ordinary Differential Equations. By
4.
5.
6.
7.
8.

Sunday Fadugba.
Numerical Methods for Engineers, 6th edition.
www.sys-bio.org
http://calculuslab.deltacollege.edu
http://community.wve.edu
http://nm.mathforcollege.com/topics/euler_method.html

13

10.0 Appendix
Coding source
clc
clf
clearall
% Mfile name
% mtl_int_sim_eulermethod.m
% Purpose
% To illustrate Euler's method applied
% to a function of the user's choosing.
% Inputs
% This is the only place in the program where the user makes the changes
% based on their wishes
% dy/dx in form of f(x,y). In general it can be a function of both
% variables x and y. If your function is only a function of x then
% you will need to add a 0*y to your function.
fcnstr= (1/(150*10^-6))*(-0.1+ max((((18*cos(120*pi*x))-2-y)/0.04),0))' ;
f=inline(fcnstr) ;
% x0, x location of known initial condition
x0=0 ;
% y0, corresponding value of y at x0
y0=0 ;
% xf, x location at where you wish to see the solution to the ODE

14

xf= 0.00004;
% n, number of steps to take
n= 2;
%h, step size
h=0.00002;
%**********************************************************************
% Displays title information
disp(sprintf('\n\nEuler Method of Solving Ordinary Differential
Equations'))
disp(sprintf('University Malaysia Sabah'))
disp('NOTE: This worksheet demonstrates the use of Matlab to illustrate ')
disp('Euler''s method, a numerical technique in solving ordinary
differential')
disp('equations.')
% Displays introduction text
disp(sprintf('\n***************************Introduction********************
********'))
disp('Euler''s method approximates the solution to an ordinary
differential')
disp('equation by using the equation expressed in the form dy/dx = f(x,y)
to')
disp('approximate the slope. This slope is used to project the solution
to')
disp('the ODE a fixed distance away.')
% Displays inputs being used
disp(sprintf('\n\n****************************Input
Data*****************************'))
disp(sprintf('
f = dy/dx '))
disp(sprintf('
x0 = initial x '))
disp(sprintf('
y0 = initial y '))
disp(sprintf('
xf = final x '))
disp(sprintf('
n = number of steps to take'))
formatshortg
disp(sprintf('\n----------------------------------------------------------------\n'))
disp(sprintf(['
f(x,y) = dy/dx = 'fcnstr]))
disp(sprintf('
x0 = %g',x0))
disp(sprintf('
y0 = %g',y0))
disp(sprintf('
xf = %g',xf))
disp(sprintf('
n = %g',n))
disp(sprintf('\n----------------------------------------------------------------'))
xa(1)=x0 ;
ya(1)=y0 ;
% Here begins the method

15

disp(sprintf('\n\n**************************Simulation*********************
********'))
for i=1:n
disp(sprintf('\nStep %g',i))
disp(sprintf('----------------------------------------------------------------'))
% Adding Step Size
xa(i+1)=xa(i)+h ;
% Calculating f(x,y) at xa(i) and ya(i)
fcn = f(xa(i),ya(i)) ;
% Using Euler's formula
ya(i+1)=ya(i)+fcn*h ;
disp('1) Evaluate the function f at the previous, values of x and y.')
disp(sprintf('
f( x%g , y%g ) = f( %g , %g ) = %g',i-1,i1,xa(i),ya(i),fcn))
disp(sprintf('2) Apply the Euler method to estimate y%g',i))
disp(sprintf('
y%g = y%g + f( x%g, y%g ) * h ',i,i-1,i-1,i-1))
disp(sprintf('
= %g + %g * %g ',ya(i),fcn,h))
disp(sprintf('
= %g',ya(i+1)))
disp(sprintf('
at x%g = %g',i,xa(i+1)))
end
% The following are the results
disp(sprintf('\n\n**************************Results************************
****'))
% The following finds what is called the 'Exact' solution
xspan = [x0 xf];
[x,y]=ode45(f,xspan,y0);
[yfi dummy]=size(y);
yf=y(yfi);
% Plotting the Exact and Approximate solution of the ODE.
holdon
xlabel('x');ylabel('y');
title('Exact and Approximate Solution of the ODE by Euler''s Method');
plot(x,y,'--','LineWidth',2,'Color',[0 0 1]);
plot(xa,ya,'-','LineWidth',2,'Color',[0 1 0]);
legend('Exact','Approximation');
disp('The figure window that now appears shows the approximate solution as
')
disp('piecewise continuous straight lines. The blue line represents the
exact')
disp('solution. In this case ''exact'' refers to the solution obtained by
the')
disp(sprintf('Matlab function ode45.\n'))
disp('While Euler''s method is valid for approximating the solutions of')
disp('ordinary differential equations, the use of the slope at one point')
disp('to project the value at the next point is not very accurate. Note
the')

16

disp('approximate value obtained as well as the true value and relative


true')
disp('error at our desired point x = xf.')
disp(sprintf('\n
Approximate = %g',ya(n+1)))
disp(sprintf('
Exact
= %g',yf))
disp(sprintf('\n
True Error = Exact - Approximate'))
disp(sprintf('
= %g - %g',yf,ya(n+1)))
disp(sprintf('
= %g',yf-ya(n+1)))
disp(sprintf('\n
Absolute Relative True Error Percentage'))
disp(sprintf('
= | ( Exact - Approximate ) / Exact | * 100'))
disp(sprintf('
= | %g / %g | * 100',yf-ya(n+1),yf))
disp(sprintf('
= %g',abs( (yf-ya(n+1))/yf )*100))
disp(sprintf('\nThe Euler approximation can be more accurate if we made
our'))
disp(sprintf('step size smaller (that is, increasing the number of
steps).\n\n'))

17

Вам также может понравиться