Beruflich Dokumente
Kultur Dokumente
In Partial Fulfillment of
The Requirements of the Course
(ECE 427L Numerical Methods)
Differentiation
SUBMITTED BY:
SAKIWAT, KYLE A.
SUBMITTED TO:
ENGR. RAUL MABITAZAN
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.
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
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
𝐴𝑢 = 𝑓
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,
• 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
In Partial Fulfillment of
The Requirements of the Course
(ECE 427L Numerical Methods)
Integration
SUBMITTED BY:
SAKIWAT, KYLE A.
SUBMITTED TO:
ENGR. RAUL MABITAZAN
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
𝑏 𝑁
∫ 𝑓(𝑥)𝑑𝑥 ≈ ∑ 𝑊𝑖 𝑓(𝑥𝑖 )
𝑎 𝑖=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
𝑏 𝑁
𝑏 − 𝑎 𝑓(𝑎) + 𝑓(𝑏)
∫ 𝑓(𝑥)𝑑𝑥 = [ + ∑ 𝑓(𝑎 + 𝑘𝑑𝑥)]
𝑎 𝑁 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:
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)
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:")
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
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
In Partial Fulfillment of
The Requirements of the Course
(ECE 427L Numerical Methods)
SUBMITTED BY:
SAKIWAT, KYLE A.
SUBMITTED TO:
ENGR. RAUL MABITAZAN
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
Rise
Slope =
Run
y1 − y 0
=
x1 − x0
= f ( x0 , y 0 )
From here
y1 = y0 + f (x0 , y0 )(x1 − x0 )
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
y2 = y1 + f (x1 , y1 )h
x2 = x1 + h
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
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 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
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
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
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
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
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)
The problem was solved again using a smaller step size. The results are given below in
Table 1.
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
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
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
In Partial Fulfillment of
The Requirements of the Course
(ECE 427L Numerical Methods)
SUBMITTED BY:
SAKIWAT, KYLE A.
SUBMITTED TO:
ENGR. RAUL MABITAZAN
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.
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:
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
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
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)
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
x4 = −0.9
I. First approximation x1 = 0.3 , x2 = 1.5 , x3 = 2.7 , x4 = −0.9 then
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
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
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
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
• 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