You are on page 1of 44

# Saint Louis University

## School of Engineering and Architecture

Department of Electronics Engineering

## A report presented to the

Electronics Engineering Department
School of Engineering and Architecture

In Partial Fulfillment of
The Requirements of the Course
(ECE 427L Numerical Methods)

Differentiation

## 7:30:00 – 10:30 T - H514

SUBMITTED BY:
SAKIWAT, KYLE A.

SUBMITTED TO:
ENGR. RAUL MABITAZAN

## MAY 15, 2018

I. Introduction

An algorithmic procedure is described which will estimate the first, second or third
order derivative of a function f(x) at a point x0, using polynomial interpolation to values of
f(x) at points on the real axis. This procedure does not require the user to provide
information about the accuracy of the function values. The procedure itself monitors the
noise level in these values and allows for the effect of noise on the estimated derivative. The
evaluation points may be restricted to one side of x 0 if f(x) makes this necessary and are
chosen either to minimize the error in the result, or to achieve a specified tolerance with as
few function evaluations as possible.

## So far, we have used the interpolating polynomial to approximate values of a function

f(x) at points where f(x) is unknown. Another use of the interpolating polynomial of equal
or even greater importance in practice is the imitation of the fundamental operations of
calculus. In all of these applications, the basic idea is extremely simple: instead of performing
the operation on the function f(x) which may be difficult or, in cases where f(x) is known at
discrete points only, impossible, the operation is performed on a suitable interpolating
polynomial. In this chapter, we consider the operation of differentiation.
II. Numerical Formulas with Programming Implementation

## Given f(x), its first derivative f’(x) is defined as:

∆𝑓(𝑥)
𝑓 ′ (𝑥) = lim
∆𝑥 → 0 ∆𝑥

The value of the derivative of f(x) can be determined using Finite Differences.
First Derivative:
• Forward Difference:
𝑓(𝑥 + ∆𝑥) − 𝑓(𝑥)
𝑓 ′ (𝑥) =
∆𝑥
• Backward Difference:
𝑓(𝑥) − 𝑓(𝑥 − ∆𝑥)
𝑓 ′ (𝑥) =
∆𝑥
• Central Difference:
𝑓(𝑥 + ∆𝑥) − 𝑓(𝑥 − ∆𝑥)
𝑓 ′ (𝑥) =
2∆𝑥

Second Derivative:
• Forward Difference:
𝑓(𝑥 + 2∆𝑥) − 2𝑓(𝑥 + ∆𝑥) + 𝑓(𝑥)
𝑓 ′ (𝑥) =
(∆𝑥)2
• Backward Difference:
𝑓(𝑥) − 2𝑓(𝑥 − ∆𝑥) + 𝑓(𝑥 − 2∆𝑥)
𝑓 ′ (𝑥) =
(∆𝑥)2
• Central Difference:
𝑓(𝑥 + 2∆𝑥) − 2𝑓(𝑥) + 𝑓(𝑥 − 2∆𝑥)
𝑓 ′ (𝑥) =
(2∆𝑥)2

## Scilab Code Representation:

clear,clc;
function fx=f(x)
fx=5*(x^3)*exp(-0.5*x)
endfunction

## function fpx=fp_forward(x, dx)

fpx=(f(x+dx)-f(x))/dx;
endfunction
fpx=fp_forward(2,10^(-4))

## function fpx=fp_backward(x, dx)

fpx=(f(x)-f(x-dx))/dx;
endfunction
fpx=fp_backward(2,10^(-4))

## function fpx=fp_central(x, dx)

fpx=(f(x+dx)-f(x-dx))/(2*dx);
endfunction
fpx=fp_central(2,10^(-4))

## function fppx=fpp_forward(x, dx)

fppx=(f(x+2*dx)-2*f(x+dx)+f(x))/(dx^2);
endfunction
fppx=fpp_forward(2,10^(-4))

## function fppx=fpp_backward(x, dx)

fppx=(f(x)-2*f(x-dx)+f(x-2*dx))/(dx^2);
endfunction
fppx=fpp_backward(2,10^(-4))

## function fppx=fpp_central(x, dx)

fppx=(f(x+2*dx)-2*f(x)+f(x-2*dx))/((2^2)*dx^2);
endfunction
fppx=fpp_central(2,10^(-4))
function fpppx=fppp_forward(x, dx)
fpppx=(f(x+3*dx)-3*f(x+2*dx)+3*f(x+dx)-f(x))/(dx^3);
endfunction
fpppx=fppp_forward(2,10^(-4))

## function fpppx=fppp_backward(x, dx)

fpppx=(f(x)-3*f(x-dx)+3*f(x-2*dx)-f(x-3*dx))/(dx^3);
endfunction
fpppx=fppp_backward(2,10^(-4))

## function fpppx=fppp_central(x, dx)

fpppx=(f(x+3*dx)-3*f(x+dx)+3*f(x-dx)-f(x-3*dx))/((2^3)*dx^3);
endfunction
fpppx=fppp_central(2,10^(-4))
III. Applications with Numerical Solutions

## 1. In an Automobile there is always an odometer and a speedometer. These two gauges

work in tandem and allow the driver to determine his speed and his distance that he
has traveled. Electronic versions of these gauges simply use derivatives to transform
the data sent to the electronic motherboard from the tires to miles per Hour(MPH)
and distance(KM).
2. Keeping with the automobile theme from the previous slide, all police officers who
use radar guns are actually taking advantage of the easy use of derivatives. When a
radar gun is pointed and fired at your care on the highway. The gun is able to
determine the time and distance at which the radar was able to hit a certain section
of your vehicle. With the use of derivative it is able to calculate the speed at which
the car was going and also report the distance that the car was from the radar gun.
3. In the business world there are many applications for derivatives. One of the most
important application is when the data has been charted on graph or data table such
as excel. Once it has been input, the data can be graphed and with the applications of
derivatives you can estimate the profit and loss point for certain ventures. The most
common application of derivative is to analyze graphs of data that can be calculated
from many different fields. Using derivative one is able to calculate the gradient at
any point of a graph.

## −𝑢′′ (𝑥) + 𝑘𝑢(𝑥) = 𝑓(𝑥), 𝑥 ∈ 𝐼

wwhere I = [0; 1]. Let {x}N+1i=0 be a uniform partition of the interval I such that
xi = ih, i = 0, 1, . . . ,N + 1; and (N + 1)h = 1. Then
−𝑢′′ (𝑥) + 𝑘𝑢(𝑥𝑖 ) = 𝑓(𝑥𝑖 ), 𝑖 = 1, . . . , 𝑁

Thus, the basic finite difference method for solving the equation involves determining the numbers is:

Or

## The equation above may be written into

𝐴𝑢 = 𝑓

Where:

This tridiagonal system of equations can be solved using the MATLAB function

It can be shown that the difference problem has a unique solution which is second order
accurate; that is,

## |𝑢(𝑥𝑖 ) − 𝑢𝑖ℎ | = 𝑂(ℎ2 ), 𝑗 = 1, . .. , 𝑁.

Sample Matlab Code of the above application:

## function boundary_value_problem (N)

x = linspace(0, pi, N+1);
f = -(sin(x) - 1);
h = pi/N;
A = zeros(N+1, N+1);
A(1, 1) = 1;
A(N+1, N+1) = 1;
for i=2:N
A(i, i-1) = -1/h/h;
A(i, i) = 2/h/h;
A(i, i+1) = -1/h/h;
end
b = zeros(N+1, 0);
b(1, 1) = 0;
b(N+1, 1) = 0;
for i=2:N
b(i, 1) = f(i);
end
u = inv(A)*b;
plot(x, u, 'go');
hold on
plot(x, -sin(x) - x.*x/2 + pi*x/2, '-k');
legend ('numerical approximation', 'true solution')
err = 0
for i=1:N+1
err = err + abs(u(i)-(-sin(x(i))-x(i)*x(i)/2 + pi*x(i)/2));
end
err/N
end
IV. Sources and References

• https://www.math.uh.edu/~jingqiu/math4364/differentiation.pdf
• https://www.sciencedirect.com/science/article/pii/0771050X8090008X
• https://www.slideshare.net/ashaf15-7473/application-of-numerical-integration-
and-differentiation-in-real-life
Saint Louis University
School of Engineering and Architecture
Department of Electronics Engineering

## A report presented to the

Electronics Engineering Department
School of Engineering and Architecture

In Partial Fulfillment of
The Requirements of the Course
(ECE 427L Numerical Methods)

Integration

## 7:30:00 – 10:30 T - H514

SUBMITTED BY:
SAKIWAT, KYLE A.

SUBMITTED TO:
ENGR. RAUL MABITAZAN

I. Introduction

## Numerical differentiation methods compute approximations to the derivative of a function

from known values of the function. Numerical integration uses the same information to
compute numerical approximations to the integral of the function. An important use of both
types of methods is estimation of derivatives and integrals for functions that are only known
at isolated points, as is the case with for example measurement data. An important difference
between differentiation and integration is that for most functions it is not possible to
determine the integral via symbolic methods, but we can still compute numerical
approximations to virtually any definite integral. Numerical integration methods are
therefore more useful than numerical differentiation methods, and are essential in many
practical situations.

We use the same general strategy for deriving numerical integration methods as we did for
numerical differentiation methods: We find the polynomial that interpolates the function at
some suitable points, and use the integral of the polynomial as an approximation to the
function. This means that the truncation error can be analyzed in basically the same way as
for numerical differentiation. However, when it comes to round-off error, integration
behaves differently from differentiation: Numerical integration is very insensitive to round-
off errors, so we will ignore round-off in our analysis.

The mathematical definition of the integral is basically via a numerical integration method,
and we therefore start by reviewing this definition. We then derive the simplest numerical
integration method, and see how its error can be analyzed. We then derive two other
methods that are more accurate, but for these we just indicate how the error analysis can be
done.

We emphasise that the general procedure for deriving both numerical differentiation and
integration methods with error analyses is the same with the exception that round-off errors
are not of must interest for the integration methods.
II. Numerical formulas with Programming Implementation

## In general, a numerical integration is the approximation of a definite integration by a

“weighted” sum of function values at discretized points within the interval of integration.

𝑏 𝑁

∫ 𝑓(𝑥)𝑑𝑥 ≈ ∑ 𝑊𝑖 𝑓(𝑥𝑖 )
𝑎 𝑖=0

where Wi is the weighted factor depending on the integration schemes used, and f(xi) is the
function value evaluated at the given point xi

Rectangular Method

-Divide the interval into N Sub intervals and Approximate each interval as rectangle.

𝑏−𝑎
𝑑𝑥 = 𝑁

Where:

N – Number of Sub-intervals
A – lower point
b – upper point.
- The integral of a function from a to b can be assumed as the summation of each area of the
rectangle within the range and is summarized in the equation below:

𝑏 𝑁
𝑏−𝑎
∫ 𝑓(𝑥)𝑑𝑥 = ∑ 𝑓(𝑎 + 𝑘𝑑𝑥)
𝑎 𝑁
𝑘=1

Trapezoidal Method

The rectangular rule can be made more accurate by using trapezoids to replace the
rectangles as shown. A linear approximation of the function locally sometimes works much
better than using the averaged value like the rectangular rule does.

It has the same algorithm as the rectangular method but this time, a trapezoid is used

## The equation can be written as follows:

𝑏 𝑁
𝑏 − 𝑎 𝑓(𝑎) + 𝑓(𝑏)
∫ 𝑓(𝑥)𝑑𝑥 = [ + ∑ 𝑓(𝑎 + 𝑘𝑑𝑥)]
𝑎 𝑁 2
𝑘=1
Simpsons Rule

Simpson’s Rule Still, the more accurate integration formula can be achieved by
approximating the local curve by a higher order function, such as a quadratic polynomial.
This leads to the Simpson’s rule and the formula is given as:

𝑏
𝑑𝑥
∫ 𝑓(𝑥)𝑑𝑥 = [𝑓(𝑎) + 3𝑓(𝑎 + 𝑑𝑥) + 𝑓(𝑎 + 2𝑑𝑥)]
𝑎 3
𝑑𝑥
+ [𝑓(𝑎 + 2𝑑𝑥) + 3𝑓(𝑎 + 3𝑑𝑥) + 𝑓(𝑎 + 4𝑑𝑥)] + ⋯
3
𝑑𝑥
+ [𝑓(𝑎 + (𝑁 − 2)𝑑𝑥) + 3𝑓(𝑎 + (𝑁 − 3)𝑑𝑥) + 𝑓(𝑎 + 12𝑑𝑥)]
3

It is to be noted that the total number of subdivisions has to be an even number in order for
the Simpson’s formula to work properly

Programming Implementation:

## • Rectangular Method (MATLAB)

clc;clear;
format long
a1 = '\nInput the Lower Limit: ';
a = input(a1);
b1 = '\nInput the Upper Limit: ';
b = input(b1);
N1='\nInput the Number of Sub-intervals: ';
N=input(N1);
dx=(b-a)/N;
k=1;
sum1=0;
sum2=0;
for i=1:N
k=a+(dx*i);
fk=10*exp(-2*k);
if(i==1)&&(i==N)
sum1=sum1+fk;
else
sum2=sum2+fk;
end
end
x=dx*sum2;
p=sprintf('\nThe integral of the function from %i to %i is equal to %f',a,b,x);
disp(p)

## • Trapezoid Method (Scilab)

deff('y=f(x)','y=(1+x^2)^0.5')
a=input("Enter Lower Limit: ")
b=input("Enter Upper Limit: ")
n=input("Enter number of sum intervals: ")
h=(b-a)/n
c=0
d=0
for i=1:(n-1)
x=a+i*h;
y=f(x)
disp([x y])
if(i==0)|(i==n)
c=c+y;
else
d=d+y;
end
end
I=(h/2)*(c+2*d)+(h/2)*(f(a)+f(b))
disp(I,"Integration by Trapezoidal Rule is:")

## • Simpson’s Rule (Scilab)

deff('y=f(x)','y=x^4')
a=input("Enter Lower Limit: ")
b=input("Enter Upper Limit: ")
n=input("Enter number of sum intervals: ")
h=(b-a)/n
add1=0
add2=0
add3=0
for i=0:n
x=a+i*h
y=f(x)
disp([x y])
if (i==0)|(i==n) then
add1=add1+y
else if (modulo(i,2)==0) then
add2=add2+y
else
add3=add3+y
end
end
end
I=(h/3)*(add1+2*add2+4*add3)
disp(I,"Integration by Simpsons (1/3)rd Rule is:")
III. Applications and Numerical Solutions

## • It helps to find the area

• Locate the centroid
• Find the arc length of a graph
• Find the surface area of a solid
• Find the volume of a solid figure
• Solve for the work done
• Solve the moment of inertia
• It is also used to find Sectional area
• Waterplane area
• Submerged volume
• Longitudinal center of floatation (LCF)
• Vertical center of buoyancy (VCB).

Instances:

1. A Small Waterplane Area Twin Hull, better known by the acronym SWATH, is a twin-
hull ship design that minimizes hull cross section area at the sea's surface. Minimizing
the ship's volume near the surface area of the sea, where wave energy is located,
maximizes a vessel's stability, even in high seas and at high speeds.
2. In geology, the structure of the interior of a planet is often illustrated using a diagram
of a cross section of the planet that passes through the planet's centre, as in the cross
section of Earth.  Cross sections are often used in anatomy to illustrate the inner
structure of an organ, as shown at left.  A cross section of a tree trunk, reveals growth
rings that can be used to find the age of the tree and the temporal properties of its
environment.
3. An object that sinks displaces an amount of fluid equal to the object's volume. Thus
buoyancy is expressed through Archimedes' principle, which states that the weight of
the object is reduced by its volume multiplied by the density of the fluid. If the weight
of the object is less than this displaced quantity, the object floats; if more, it sinks. The
amount of fluid displaced is directly related (via Archimedes' Principle) to its volume.
In the case of an object that sinks (is totally submerged), the volume of the object is
displaced. In the case of an object that floats, the amount of fluid displaced will be
equal in weight to the displacing object .
4. SUBMERGED VOLUME : Integration of sectional area over the length of ship. x y
5. It is used to find the center of water plane area (i.e.) distance from reference point to
center of floatation.
IV. Sources and References
• http://www.uio.no/studier/emner/matnat/math/MAT-
INF1100/h11/kompendiet/chap12.pdf
• http://www.jamalalsakran.me/NumAnalysis/Chapter7.pdf
• https://www.slideshare.net/GOWTHAMGOWSIK98/numerical-integration-and-its-
applications
Saint Louis University
School of Engineering and Architecture
Department of Electronics Engineering

## A report presented to the

Electronics Engineering Department
School of Engineering and Architecture

In Partial Fulfillment of
The Requirements of the Course
(ECE 427L Numerical Methods)

## 7:30:00 – 10:30 T - H514

SUBMITTED BY:
SAKIWAT, KYLE A.

SUBMITTED TO:
ENGR. RAUL MABITAZAN

## MAY 15, 2018

I. Introduction
Differential equations can describe nearly all systems undergoing change. They are
ubiquitous is science and engineering as well as economics, social science, biology, business,
health care, etc. Many mathematicians have studied the nature of these equations for
hundreds of years and there are many well-developed solution techniques. Often, systems
described by differential equations are so complex, or the systems that they describe are so
large, that a purely analytical solution to the equations is not tractable. It is in these complex
systems where computer simulations and numerical methods are useful.

The techniques for solving differential equations based on numerical approximations were
developed before programmable computers existed. During World War II, it was common to
find rooms of people (usually women) working on mechanical calculators to numerically
solve systems of differential equations for military calculations. Before programmable
computers, it was also common to exploit analogies to electrical systems to design analog
computer store study mechanical, thermal, or chemical systems. As programmable
computers have increased in speed and decreased in cost, increasingly complex systems of
differential equations can be solved with simple programs written to run on a common PC.
Currently, the computer on your desk can tackle problems that were inaccessible to the
fastest supercomputers just 5 or 10 years ago.

This chapter will describe some basic methods and techniques for programming simulations
of differential equations. First, we will review some basic concepts of numerical
approximations and then introduce Euler’s method, the simplest method. We will provide
details on algorithm development using the Euler method as an example. Next we will
discuss error approximation and discuss some better techniques. Finally we will use the
algorithms that are built into the MATLAB programming environment.

The fundamental concepts in this chapter will be introduced along with practical
implementation programs. In this chapter we will present the programs written in the
MATLAB programming language. It should be stressed that the results are not particular to
MATLAB; all the programs in this chapter could easily be implemented in any programming
language, such as C, Java, or assembly. MATLAB is a convenient choice as it was designed for
scientific computing (not general purpose software development) and has a variety of
numerical operations and numerical graphical display capabilities built in. The use of
MATLAB allows the student to focus more on the concepts and less on the programming.
II. Numerical Algorithm with Programming Implementation
• Euler’s Method
Euler’s method is a numerical technique to solve ordinary differential equations of the form

= f ( x, y ), y (0) = y 0
dy
(1)
dx
So only first order ordinary differential equations can be solved by using Euler’s method.

At x = 0 , we are given the value of y = y 0 . Let us call x = 0 as x 0 . Now since we know the

slope of y with respect to x , that is, f (x, y ) , then at x = x0 , the slope is f ( x0 , y 0 ) . Both x0

True value

y1,
Φ Predicted

value

Step size, h

## So the slope at x = x0 as shown in Figure 1 is

Rise
Slope =
Run

y1 − y 0
=
x1 − x0

= f ( x0 , y 0 )
From here

y1 = y0 + f (x0 , y0 )(x1 − x0 )

## Calling x1 − x0 the step size h , we get

y1 = y0 + f (x0 , y0 )h (2)

One can now use the value of y1 (an approximate value of y at x = x1 ) to calculate y 2 , and

## that would be the predicted value at x2 , given by

y2 = y1 + f (x1 , y1 )h

x2 = x1 + h

## Based on the above equations, if we now know the value of y = yi at x i , then

yi +1 = yi + f (xi , yi )h (3)

This formula is known as Euler’s method and is illustrated graphically in Figure 2. In some
books, it is also called the Euler-Cauchy method.

True Value

Φ

yi h
Step size
x
xi xi+1

## Figure 2 General graphical interpretation of Euler’s method.

Sample Code for Euler’s Method (Matlab)

clear;

y=1;

dt = 0.5;

time = 0;

t_final = 2;

Nsteps = rund(t_final/dt);

Plot(time,y,’*’);

Hold on;

For i=1:Nsteps

y = y – dt*y;

time = time + dt

plot(time,y,’*’);

end

t = linspace(0,t_final,100);

y=exp(-t);

plot(t,y,’r’)

xlael(‘time’);

ylabel(‘y’);

## • Modified Euler’s Method

Modified Euler’s Method is a popular method of numerical analysis for integration of initial
value problem with the best accuracy and reliability. It solves ordinary differential equations
(ODE) by approximating in an interval with slope as an arithmetic average. This method is a
simple improvement on Euler’s method in function evaluation per step but leads to yield a
second order method.
Derivation of Modified Euler’s Method: Consider y which is the function of t and solution to
an ordinary differential equation. y can be graphically represented as follows:

h = (xn – x0)/n

## y( t + h ) = y (t) + h/2 [ dy(t)/dt + dy (t +h ) / dt ] + O(h3)

The values of O(h3) and other higher terms are very small and generally neglected. Based on
this derivation, we’ll work out the code for Modified Euler’s method in Matlab.
Sample code for Modified Euler’s Method

function a= eular( df )
%df = @(x, y) -2xy^2

% for calculating value of dy/dx at some particular pt using modified euler's method

## x0 = input('Enter initial value of x : ');

y0 = input ('Enter initial value of y : ');
x1 = input( 'Enter thevalue of x at which y is to be calculated : ');
tol = input( 'Enter desired level of accuracy in the final result : ');
% calaulating the value of h

n =ceil( (x1-x0)/sqrt(tol));
h = ( x1 - x0)/n
%loop for calculating values

for k = 1 : n
X(1,1) = x0; Y (1,1) = y0;
X( 1, k+1) = X(1,k) + h;
y_t = Y(1,k) + h* feval( df , X(1,k) , Y(1,k));% Eular's formula
Y(1 ,k+1) = Y(1,k) + h/2* (feval( df , X(1,k) , Y(1,k)) + feval( df , X(1,k) + h , y_t ) ) ;
%improving results obtained by modified Eular's formula
while abs( Y(1,k+1) - y_t ) > h
y_t = Y(1,k) + h*feval( df , X(1,k) , Y(1,k+1));
Y( 1 ,k+1) = Y(1,k) + h/2* (feval( df , X(1,k) , Y(1,k)) + feval( df , X(1,k) + h , y_t ) );
end
end
%displaying results

## fprintf( 'for \t x = %g \n \ty = %g \n' , x1,Y(1,n+1))

%displaying graph

x = 1:n+1;
y = Y(1,n+1)*ones(1,n+1) - Y(1,:);
plot(x,y,'b')
xlabel = (' no of intarval ');
ylabel = ( ' Error ');
III. Applications and Numerical Solutions

## Solving Definite Integrals Using Euler’s Method

Let us suppose you want to find the integral of a function f (x )

b
I =  f (x )dx .
a

Both fundamental theorems of calculus would be used to set up the problem so as to solve it as an
ordinary differential equation.

The first fundamental theorem of calculus states that if f is a continuous function in the interval [a,b],
and F is the antiderivative of f , then

 f (x )dx = F (b) − F (a )
a

The second fundamental theorem of calculus states that if f is a continuous function in the open
interval D , and a is a point in the interval D , and if
x
F (x ) =  f (t )dt
a

then

F (x) = f (x)

at each point in D .
b
Asked to find  f (x )dx , we can rewrite the integral as the solution of an ordinary differential
a

equation (here is where we are using the second fundamental theorem of calculus)

= f ( x ), y (a ) = 0,
dy
dx

where then y(b) (here is where we are using the first fundamental theorem of calculus) will give the
b
value of the integral  f (x )dx .
a

## Using Numerical Euler’s Method in Temperature Applications

A ball at 1200K is allowed to cool down in air at an ambient temperature of 300K .
Assuming heat is lost only due to radiation, the differential equation for the temperature of
the ball is given by
d
dt
( )
= −2.2067  10 −12  4 − 81 108 ,  (0) = 1200K

where  is in K and t in seconds. Find the temperature at t = 480 seconds using Euler’s
method. Assume a step size of h = 240 seconds.
Solution
d
dt
(
= −2.2067 10 −12  4 − 81 108 )
(
f (t , ) = −2.2067 10−12  4 − 81 108 )
Per Equation (3), Euler’s method reduces to
 i +1 =  i + f (ti , i )h
For i = 0 , t 0 = 0 ,  0 = 1200

1 =  0 + f (t 0 , 0 )h
= 1200 + f (0,1200)  240

( (
= 1200 + − 2.2067 10−12 12004 − 81 108  240 ))
= 1200 + (− 4.5579)  240
= 106.09 K
1 is the approximate temperature at
t = t1 = t 0 + h = 0 + 240 = 240

1 =  (240)  106.09 K
For i = 1 , t1 = 240 , 1 = 106.09

2 = 1 + f (t1 ,1 )h
= 106.09 + f (240,106.09)  240

( (
= 106.09 + − 2.2067 10−12 106.094 − 81 108  240 ))
= 106.09 + (0.017595)  240
= 110.32 K
 2 is the approximate temperature at
t = t 2 = t1 + h = 240+ 240 = 480
 2 =  (480)  110.32 K
Figure 3 compares the exact solution with the numerical solution from Euler’s method for
the step size of h = 240 .

1400
Temperature, θ (K)

1200

1000
Exact Solution
800

600

400

200
h =240

0
0 100 200 300 400 500

Time, t (sec)

## Figure 3 Comparing the exact solution and Euler’s method.

The problem was solved again using a smaller step size. The results are given below in
Table 1.

## 480 -987.81 1635.4 252.54

240 110.32 537.26 82.964
120 546.77 100.80 15.566
60 614.97 32.607 5.0352
30 632.77 14.806 2.2864
Figure 4 shows how the temperature varies as a function of time for different step sizes.
1500

Temperature, θ (K)
1000 Exact solution

500
h =120
h =240
0
0 100 200 300 400 500
-500
Time, t (sec) h = 480
-1000

-1500

## Figure 4 Comparison of Euler’s method with the exact solution

for different step sizes.

The values of the calculated temperature at t = 480s as a function of step size are plotted in
Figure 5.

800
Temperature, θ (K)

400

0
0 100 200 300 400 500
-400
Step size, h (s)
-800

-1200

## Figure 5 Effect of step size in Euler’s method.

The exact solution of the ordinary differential equation is given by the solution of a non-
linear equation as
 − 300
0.92593ln − 1.8519tan −1 (0.333 10− 2  ) = −0.22067 10−3 t − 2.9282 (4)
 + 300
The solution to this nonlinear equation is
 = 647.57 K
It can be seen that Euler’s method has large errors. This can be illustrated using the Taylor
series.

1 d2y 1 d3y
yi +1 = yi +
dy
(xi +1 − xi ) + (xi +1 − xi )
2
+ (xi +1 − xi )3 + ... (5)
dx xi , yi 2! dx 2 xi , yi
3! dx 3 xi , yi

## f ' ( xi , y i )(xi +1 − xi ) + f ' ' ( xi , y i )(xi +1 − xi ) + ...

1 1
= y i + f ( xi , y i )( xi +1 − xi ) +
2 3
(6)
2! 3!
As you can see the first two terms of the Taylor series
yi +1 = yi + f (xi , yi )h
are Euler’s method.
The true error in the approximation is given by
f (xi , yi ) 2 f (xi , yi ) 3
Et = h + h + ... (7)
2! 3!
The true error hence is approximately proportional to the square of the step size, that is, as
the step size is halved, the true error gets approximately quartered. However from Table 1,
we see that as the step size gets halved, the true error only gets approximately halved. This
is because the true error, being proportioned to the square of the step size, is the local
truncation error, that is, error from one point to the next. The global truncation error is
however proportional only to the step size as the error keeps propagating from one point
to another.
IV. Sources and References
• http://faculty.olin.edu/bstorey/Notes/DiffEq.pdf
• http://nm.mathforcollege.com/topics/euler_method.html
• https://www.codewithc.com/modified-eulers-method-matlab-program/
Saint Louis University
School of Engineering and Architecture
Department of Electronics Engineering

## A report presented to the

Electronics Engineering Department
School of Engineering and Architecture

In Partial Fulfillment of
The Requirements of the Course
(ECE 427L Numerical Methods)

## 7:30:00 – 10:30 T - H514

SUBMITTED BY:
SAKIWAT, KYLE A.

SUBMITTED TO:
ENGR. RAUL MABITAZAN

## MAY 15, 2018

I. Introduction
Although some applications of differential equations involve only a single first-order
equation, most applications involve a system of several such equations or higher-order
equations. In this report, we consider systems of first-order equations, showing how Euler’s
method applies to such systems. Numerical treatment of higher-order equations can be
carried out by first converting them to equivalent systems of first order equations.

In recent years, many different methods and different basis functions have been used to
estimate the solution of the system of integral equations, such as Adomian decomposition
method , Taylor’s expansion method , homotopy perturbation method, projection method
and Nystrom method , Spline collocation method, Runge–Kutta method , sinc method, Tau
method , block-pulse functions and operational matrices .

Systems of linear equations have a wide range of applications in both theoritical and
practical sciences. Our study attempts to give a brief introduction to the numerical solutions
of the linear systems together with some important theorems in linear algebra. Several
algorithms for solving linear systems are developed using Fortran 77. Partial pivoting is
introduced to achieve accuracy and applicability. L U decomposition is studied and the
operation count for Gaussian elimination is given and compared to other methods. The
programs are then tested with an ill-conditioned system and a nuclear reactor problem.
Errors in the discretizations are estimated.
II. Numerical Equations with Programming Implementation
Scilab has a very important and useful in-built function ode() which can be used to evaluate
an ordinary differential equation or a set of coupled first order differential equations.

## The syntax is as follows:

y=ode(y0,x0,x,f)
where,
y0=initial value of y
x0=initial value of xx=value of x at which you want to calculate y.

The following examples illustrate the use of the ode to solve a given differential equation:

## Sample Code (Scilab)

funcprot(0)
clf;
function dx=f(x, y)
dx=exp(-x);
endfunction
y0=0;
x0=0;
x=[0:0.5:10];
sol=ode(y0,x0,x,f);
plot2d(x,sol,5)
xlabel('x');
ylabel('y(x)');
xtitle('y(x) vs. x')
funcprot(0)
clf;
function dx=f(x, y)
dx=x^2-exp(-x)*y;
endfunction
y0=0;
x0=0;
x=[0:0.5:10];
sol=ode(y0,x0,x,f);
plot2d(x,sol,5)
xlabel('x');
ylabel('y(x)');
xtitle('y(x) vs. x');
III. Applications with Numerical Solutions
1). Jacobi method
The method is illustrated by taking an example
a11 x + a12 y + a13 z = b1 

a21 x + a22 y + a23 z = b2 .....(1)
a31 x + a32 y + a33 z = b3 

## After division by suitable constants transposition the equation can be

b1 a12 a 
x= − y − 13 z 
a11 a11 a11 
b a a 
y = 2 − 21 x − 23 z ......( 2)
a22 a22 a22 
b a a 
z = 3 − 31 x − 32 y 
a33 a33 a33 

## Let us assume x = 0, y = 0, z = 0 as first approximation, substituting the values of x, y, z on

b1 b b
the right hand side of (2), we get x = , y = 2 , z = 3 this is the second approximation to
a11 a 22 a33
the solution of the equations again substituting these values of x, y, z in (2) we get a third
approximation. The process is repeated till two successive approximations are equal or
nearly equal.
Note: Condition for using the iterative method is that the coefficients in the leading diagonal
are large compared to the other if these are not so, the interchanging the equations we can
make the leading diagonal dominant diagonal.
Example 1: Solve by Jacobi method
10x1 − 2 x2 − x3 − x4 = 3 
− 2 x1 + 10x2 − x3 − x4 = 15 

......( 3)
− x1 − x2 + 10x3 − 2 x4 = 27
− x1 − x2 − 2 x3 + 10x4 = −9
Solution: Given equations
x1 = 0.3 + 0.2 x2 + 0.1x3 + 0.1x4 ....(3.1)
x2 = 1.5 + 0.2 x1 + 0.1x3 + 0.1x4 ....(3.2)

## On substituting x2 = x3 = x4 = 0 in equation (3.1), we get

x1 = 0.3
On substituting x1 = x3 = x4 = 0 in equation (3.2), we get

x2 = 1.5
On substituting x1 = x2 = x4 = 0 in equation (3.3), we get

x3 = 2.7

## On substituting x1 = x2 = x3 = 0 in equation (3.4), we get

x4 = −0.9
I. First approximation x1 = 0.3 , x2 = 1.5 , x3 = 2.7 , x4 = −0.9 then

## On substituting x2 = 1.5 , x3 = 2.7, x4 = −0.9 in equation (3.1), we get

x1 = 0.78
On substituting x1 = 0.3, x3 = 2.7 , x4 = −0.9 in equation (3.2), we get

x2 = 1.74
On substituting x1 = 0.3, x2 = 1.5 , x4 = −0.9 in equation (3.3), we get
x3 = 2.7

## On substituting x1 = 0.3 , x2 = 1.5 , x3 = 2.7 in equation (3.4), we get

x4 = −0.18
Repeating same above steps for second, third, fourth approximation, and so on.
The result we get are shown in the table below:
n x1 x2 x3 x4

## 1 0.3 1.5 2.7 −0.9

2 0.78 1.74 2.7 −0.18

## Then actual values are x1=1.0, x2 =2.0, x3=3.0, x4 = 0.0

2). Gauss – Seidel method
Gauss-Seidel method, the same set of values of equation (3) is used to verify the result. Here
we illustrate that while using this method we have to do less calculation and utilize minimum
time to iterate the problem to get appropriate result as compare to Jacobi method. We know
say that Gauss-Seidel method is a modification of Jacobi method.
The method is illustrated by taking an example
a11 x + a12 y + a13 z = b1 

a21 x + a22 y + a23 z = b2 ....( 4)
a31 x + a32 y + a33 z = b3 

After division by suitable constants and transposition, the equation can be written as
b1 a12 a 
x= − y − 13 z 
a11 a11 a11 
b a a 
y = 2 − 21 x − 23 z ....( 4.1)
a22 a22 a22 
b a a 
z = 3 − 31 x − 32 y 
a33 a33 a33 

Step1. First we put y = z = 0 in first equations (4.1) and x = c1 . Then in second equations

we put of this values of x i.e c1 and z = 0 , and obtain y , in the third equation (4.1). We use
the values of x and y obtain earlier to get z .
Step2. We repeat the above procedure. In first equations we put values of y and z obtain in
step 1, and predetermine x . By using the new values of x and value of z obtained
In step 1 we predetermine y and so on.
In other word, the latest values of the unknowns are used in each step.
Consider the following equations
a1 x + b1 y + c1 z = d1
a 2 x + b2 y + c 2 z = d 2
a3 x + b3 y + c3 z = d 3

## The above equations can be rewritten as

1
x= [d1 − b1 y − c1 z ]
a1
1
y= [d 2 − a 2 x − c 2 z ]
b2
1
z= [d 3 − a3 x − b3 y ]
c3

Initial approximations
x = x0 , y = y 0, z = z 0

To find x = x1
1
x1 = [d 1 − b1 y 0 − c1 z 0 ]
a1

To find y = y1 , put x = x1 , z = z 0
1
y1 = [d1 − a 2 x1 − c 2 z 0 ]
b1

To find
z = z1 , put x = x1 , y = y1
1
z1 = [d 3 − a 3 x1 − b3 y1 ] and so on.
c1

## Note: 1. The convergence of Gauss-Seidel method is twice as fast as in Jacobi method.

2. If the absolute value of largest coefficient is greater than the sum of the absolute value
of the entire remaining coefficient than the method converses for any initial
approximation.
Example2: Solve equations (3) by Gauss-Seidel method
10x1 − 2 x2 − x3 − x4 = 3
− 2 x1 + 10x2 − x3 − x4 = 15
− x1 − x2 + 10x3 − 2 x4 = 27
− x1 − x2 − 2 x3 + 10x4 = −9
Solution: Given equations
x1 = 0.3 + 0.2 x2 + 0.1x3 + 0.1x4

## The result are given in the table.

n x1 x2 x3 x4
1 0.3 1.56 2.886 −0.1368
2 0.8869 1.9523 2.9566 −0.248
3 0.9836 1.9899 2.9924 −0.0042
4 0.9968 1.9982 2.9987 −0.0008
5 0.9994 1.9997 2.9998 −0.0001
6 0.9999 1.9997 3.0 0.0
7 1.0 2.0 3.0 0.0
8 1.0 2.0 3.0 0.0

## Then actual values are x1=1.0, x2 =2.0, x3=3.0, x4 = 0.0

IV. Sources and References

• http://homepage.divms.uiowa.edu/~atkinson/papers/NAODE_Book.pdf
• https://www.sciencedirect.com/science/article/pii/S0898122111003695
• https://sms.math.nus.edu.sg/smsmedley/Vol-20-
1/Numerical%20solutions%20of%20systems%20of%20linear%20equations(VB%
20Yap,%20Q%20Sheng).pdf
• http://www.bragitoff.com/2016/02/first-order-linear-differential-equations-ode-
in-scilab/
• NUMERICAL SOLUTION OF SYSTEM OF LINEAR EQUATIONS BY ITERATIVE
METHODS by Atendra Singh Yadav*, Ashish Kumar, Department of Mathematics &
Statistics, Sam Higginbottom University of Agriculture, Technology & Sciences
Allahabad-211007, U.P., India