home work ii
TRANSCRIPT
1 | P a g e Richardson's Extrapolation
Numerical Methods (COSC 607)
Home Work II
Richardson's Extrapolation First and second derivatives approximation
Group No 1 Group Members:-
1. Biruk Ambachewu 2. Ayalnesh Tigabie 3. Admasu Chane 4. Hidya Nurhusen 5. Wasie Legesse 6. Abebe Alemu Submitted by:-
Name Abebe Alemu Balcha ID No. GSR/3003/08
Submitted to:- Teacher Prof. Okey Oseloka Onyejekwe July , 2016
2 | P a g e Richardson's Extrapolation
Table of Contents
1. Introduction .......................................................................................................................................... 3
2. Overview ............................................................................................................................................... 3
2.1. Taylor's series ................................................................................................................................ 3
2.2. Extrapolation ................................................................................................................................. 7
3. Scope of work........................................................................................................................................ 8
4. Problem Definition One ........................................................................................................................ 8
4.1. Richardson's' Extrapolation using centered formula for First Derivatives .................................... 9
4.1.1. Part I: - Working By hand ...................................................................................................... 9
4.1.2. Analysis on Problem one ..................................................................................................... 15
4.1.3. PART II: - Computer Program using MATLAB ...................................................................... 16
4.2. Richardson's' Extrapolation using centered formula for Second Derivatives ............................. 22
4.2.1. PART I:- Working by Hand .................................................................................................. 22
4.2.2. PART II: - Computer Program using MATLAB ...................................................................... 28
5. Problem definition Two ...................................................................................................................... 32
5.1. Richardson's Extrapolation first derivatives for even power Order of h .................................... 32
5.1.1. PART I :- working by hand ................................................................................................... 32
5.1.2. PART II: - Computer Program using MATLAB ...................................................................... 42
5.2. Richardson's Extrapolation Using three point Second Derivatives ............................................. 46
5.2.1. PART I: - working by hand ................................................................................................... 46
5.2.2. PART II: - Computer Program using MATLAB ...................................................................... 49
6. Observation ......................................................................................................................................... 53
Richardson extrapolation algorithm for central differences ................................................................ 53
3 | P a g e Richardson's Extrapolation
1. Introduction This paper is prepared for numerically finding Richardson's extrapolation using centered
formula for First derivatives and second derivatives, in first, second and third orders, by
changing and dividing equal fractions, the step size h towards zero. This helps us to
extrapolate the first and second derivatives to approximate the first and second derivatives at
the reference point x.
2. Overview
2.1. Taylor's series
Taylor series is a representation of a function as an infinite sum of terms that are
calculated from the values of the function's derivatives at a single point. A Taylor series
is a series expansion of a function about a point. A one-dimensional Taylor series is an
expansion of a real function about a point is given by
'' (3) ( )' 2 3( ) ( ) ( )
( ) ( ) ( )( ) ( ) ( ) ... ( )2! 3! !
nnf a f a f a
f x f a f a x a x a x a x an
A series expansion is a representation of a particular function as a sum of powers in one
of its variables, or by a sum of powers of another (usually elementary) function .
Taylors series use for
Evaluating definite Integrals: Some functions have no antiderivative which can be
expressed in terms of familiar functions. This makes evaluating definite integrals of
these functions difficult because the Fundamental Theorem of Calculus cannot be
used. If we have a polynomial representation of a function, we can oftentimes use that
to evaluate a definite integral.
Understanding asymptotic behavior: Sometimes, a Taylor series can tell us useful
information about how a function behaves in an important part of its domain.
Understanding the growth of functions
Solving differential equations
The applications of Taylor series is mainly to approximate ugly functions into nice
ones (polynomials)!
Taylor series provide the basic method for computing transcendental functions such
as ex, sinx, and cosx.
4 | P a g e Richardson's Extrapolation
All of computational science is built on Taylor's theorem
'' (3) ( )2 3
'
( ) ( ) ( )( ) ( ) ( ) ( ) ... ( )
2! 3! !( )
( )
nnf a f a f a
f x f a x a x a x an
f ax a
,
We can use Taylor series to find approximation to the first and second derivatives of f(x)
at the point x (called reference point)
For a given step size h we can have the following formula that derived from Taylors
series
I.
'' 2 3 3'
'' 2 3 3
'
'' 2 3 3'
( ) ( )( ) ( ) ( ) ...
2! 3!
( ) ( )( ) ( ) ( ...)
2! 3!( )
( ) ( ) ( ) ( )( ) , ( ...)
2! 3!
f x h f x hf x h f x f x h
f x h f x hf x h f x
f xh
f x h f x f x h f x hf x where error
h
' ( ) ( )( )
f x h f xf x
h
-------------------------- ---------eq (1)
Called FORWARD DIFFERENCE FORMULA
II.
'' 2 3 3'
'' 2 3 3
'
'' 2 3 3'
( ) ( )( ) ( ) ( ) ...
2! 3!
( ) ( )( ) ( ) ...)
2! 3!( )
( ) ( ) ( ) ( )( ) , ...)
2! 3!
f x h f x hf x h f x f x h
f x h f x hf x f x h
f xh
f x f x h f x h f x hf x where error
h
' ( ) ( )( )
f x f x hf x
h
-------------------------------------------eq (2)
5 | P a g e Richardson's Extrapolation
Called backward difference formula
III. Add the last statement of the first and the second expressions we will have the
following expression called Central Difference Formula for estimating first
derivatives
'
'
'
( ) ( )( )
( ) ( )( ) ,
( ) ( ) ( ) ( )2 ( )
f x h f xf x
h
f x f x hf x
h
f x h f x f x f x hf x
h
' ( ) ( )( )
2
f x h f x hf x
h
-------------------------------------- eq(3)
IV. To get the Second derivatives and lets rewrite the first and second expressions as
follows
'
'
( ) ( ) ''( )( )
2
( ) ( ) ''( )( )
2
f x h f x f x hf x
h
f x f x h f x hf x
h
Let's subtract the first one from the second one and we will have
6 | P a g e Richardson's Extrapolation
( ) ( ) ''( ) ( ) ( ) ''( )( )
2 2
( ) ( ) ''( ) ( ) ( ) ''( )( )
2 2
( ) ( ) ( ) ( ) ''( ) ''( )0
2 2
''( ) ( ) 2 ( ) ( )
2
f x h f x f x h f x f x h f x h
h h
f x h f x f x h f x f x h f x h
h h
f x h f x f x f x h f x f xh h
h h h h
f x f x h f x f x hh
h h h
Thus 2
( ) 2 ( ) ( )''( )
f x h f x f x hf x
h
------------------------------------ eq(4)
V. Order of the error:- to get the order of the error O(h), let's start again form the
forward, backward difference method and finally we can deduce the central
difference methods. Which is
VI. Forward Difference
2
2
( ) ( ) '( ) ( )
'( ) ( ) ( ) ( )
( ) ( )'( ) ( )
f x h f x f x h O h
f x h f x h f x O h
f x h f xf x O h
h
so that here
the order is in the order of h
VII. Back ward difference
2
2
( ) ( ) '( ) ( )
'( ) ( ) ( ) ( )
( ) ( )'( ) ( )
f x h f x f x h O h
f x h f x f x h O h
f x f x hf x O h
h
here is also
it is in the order of h or which is call is first order
VIII. Central difference
(2) 2 (3) 3 (4) 4
(2) 2 (3) 3 (4) 4
( ) ( ) ( )( ) ( ) '( ) ...
2! 3! 4!
( ) ( ) ( )( ) ( ) '( ) ...
2! 3! 4!
f x h f x h f x hf x h f x f x h
f x h f x h f x hf x h f x f x h
subtract From the above expression s a and b, we have down and we will get the
following expressions
7 | P a g e Richardson's Extrapolation
(3) 3
2
( )( ) ( ) 2 '( ) 2 ...
3!
( ) ( )'( ) ( )
2
f x hf x h f x h f x h
f x h f x hf x O h
h
Here it is in the order of two, for small h, or if the step size h decreases, we will
have more accurate value, or the error will be very small. So that, the central
difference formula is more accurate than other two formulas.
IX. Let's make the forward difference to have second order
' ( ) ( ) ''( )( )
2
f x h f x f x hf x
h
Taylor series and equation 1
Substitute equation 4 in the second derivatives, and we would have
2 12
1
( ) 2 ( ) ( )( ) ( )
( )2
i i i
i ii
f x f x f xf x f x hf x h
h
2 1( ) 4 ( ) 3 ( )( )
2i i i
i
f x f x f xf x
h
--------------------------eq (5)
Where xi is reference point
Here by substitution of the second derivatives we improve the accuracy y
to order two O(h2)
2.2. Extrapolation Extrapolation: is the process of estimating, beyond the original observation range, the
value of a variable on the basis of its relationship with another variable. It is similar to
interpolation, which produces estimates between known observations, but extrapolation is
subject to greater uncertainty and a higher risk of producing meaningless results.
Extrapolation may also mean extension of a method, assuming similar methods will be
applicable. Extrapolation may also apply to human experience to project, extend, or
expand known experience into an area not known or previously experienced so as to
arrive at a (usually conjectural) knowledge of the unknown
Numerical methods approximates or (extrapolates) to some value, for example from
Taylors first derivatives and central difference formula
8 | P a g e Richardson's Extrapolation
F(h) will approximate to ( ) ( )
( ) '( )2
f x h f x hF h f x
h
-----------------eq(6)
2 4 61 1 2 3( ) ...F h R C h C h C h Where
0lim ( )h
R F h
There for Richardson's Extrapolation formula for even power error series is given by
1
( ) ( )2( ) ( ) , 1,2,...
2 4 1
i i
i i i
hF F h
hF h F wherei
--------------------------------------------eq(7)
And for All power error series the Extrapolation Formula is given by
1
( ) ( )2( ) ( ) , 1,2,...
2 2 1
i i
i i i
hF F h
hF h F where i
-----------------------------------------eq(8)
3. Scope of work In Richardson's Extrapolation we can do first and second derivatives in Forward,
Backward and Centered formula for this paper is working only with centered formula. So
that the scope of this work is for the given problem, finding first and second derivatives
using Richardson's extrapolation using centered formula, to determining how the error is
minimized by approximating the step size h to zero. Here the work will be done first by
hand calculation; next I will write a MATLAB code and Plot a graph to compare the
derivative of the function at the given reference point with respect to the step size.
4. Problem Definition One Using Richardson's Extrapolation Centered formula for the function
3( ) cos( ),f x x x With reference point x=2.3
a. Calculate by hand and compare the result with the following given table
b. Prepare an algorithm based on Richardson's Extrapolation centered formula
c. Write a Matlab code and analyze the result with that has done by hand
Extrapolation Table h F_1's F_2's F_3's F-4's 1 -18.03738 1/2 -19.35862 -19.79904 1/4 -19.58246 -19.65707 -19.64761 1/8 -19.63120 -19.64745 -19.64681 -19.64680
9 | P a g e Richardson's Extrapolation
Solution
4.1. Richardson's' Extrapolation using centered formula for First Derivatives
4.1.1. Part I: - Working By hand
4.1.1.1. First Order F_1's
Step 1- For step size h=1, and we have reference point x=2.3 the first derivative with order h
From eq(5) we have
2 41 1 2
( ) ( )( ) '( ) ...
2
f x h f x hF h f x C h C h
h
Substitute x and h value in the equation
1
(2.3 1) (2.3 1)(1)
2(1)
f fF
1
(3.3) (1.3)(1)
2(1)
f fF
3 3
1
3.3 cos(2.3) 1.3 cos(1.3)(1)
2(1)F
1
35.937cos(2.3) 2.197cos(1.3)(1)
2(1)F
1
35.937( 0.98747977) 2.197(0.26749883)(1)
2(1)F
1
35.48706049 0.58769493(1)
2F
1
35.48706049 0.58769493 36.07475542(1)
2 2F
There for we have 1(1) 18.037377F ------------------------------------exp (1)
Step 2- For step size h=0.5, and we have reference point x=2.3 the first derivative with order h
x+h=2.3+0.5=2.8 and x-h=2.3-0.5=1.8
3 3
1
2.8 cos(2.8) 1.8 cos(1.8)0.5
2 0.5F
1
21.952cos(2.8) 5.892cos(1.8)0.5
2 0.5F
1
20.68366482 ( 1.32504262)0.5
2 0.5F
1
20.68366482 1.32504262 19.358622200.5
2 0.5 1F
1 0 .5 1 9 .3 5 8 6 2F --------------------------------------------------------exp(2)
10 | P a g e Richardson's Extrapolation
Step 3- For step size h=0.25, reference point x=2.3 the first derivative with order h
Here x+h=2.3+0.25=2.55 and x-h=2.3-0.25=2.05, substituting to the equation we have
1
(2.55) (2.05)14 12
4
f fF
3 3
1
2.55 cos(2.55) 2.05 cos(2.05)0.25
2 0.25F
1
16.581375cos(2.55) 8.615125cos(2.05)0.25
2 0.25F
1
13.76342894 3.97219887 9.781230070.25
2 0.25 0.5F
1 0.25 19.58246F ------------------------------------------------------------------exp(3)
Step 4- For step size h=0.125, reference point x=2.3 the first derivative with order h
Here x+h=2.3+0.125=2.425 and x-h=2.3-0.125=2.175
1
(2.425) (2.175)18 12
8
f fF
3 3
1
2.425 cos(2.425) 2.175 cos(2.175)0.125
2 0.125F
1
14.26051556cos(2.425) 10.28910934cos(2.175)0.125
2 0.125F
1
14.26051556( 0.75404811) 10.28910934( 0.56810692)0.125
2 0.125F
1
10.75311489 ( 5.84531419)0.125
2 0.125F
1
10.75311489 ( 5.84531419) 4.907800700.125
2 0.125 0.25F
1
4.907800700.125 19.63120
0.25F
1 0.125 19.63120F ------------------------------------------------------------exp(4)
11 | P a g e Richardson's Extrapolation
4.1.1.2. Second Order F_2's
From equation 7 above we have 1
( )2
( )2 4 1
j j
j j j
hF F h
hF h F
1, 2,3,...j
Step 1:- at j=1 and step size h=0.5
From above calculation we do have 12
hF
= -19.358622 and 1( )F h = -18.037377
1 1
1 1 1
( )2
( )2 4 1j
hF F h
hF h F
2 1
19.358622 ( 18.037377)(0.5) 19.358622
4 1F
2
19.358622 18.037377(0.5) 19.358622
4 1F
2
1.32124(0.5) 19.358622
3F
2 (0.5) 19.358622 0.44041F
2 (0.5) 19.79903F ---------------------------------------------------------------exp(5)
Step 2:- at j=1 and step size h=0.25
1 1
2 1
1 4 2
4 4 4 1j
h hF F
hF F
for j=2 and h=1/4 or h=0.25
14
hF
=-19.58246, 12
hF
=-19.35862
1 1
2 1 1
1 4 2
4 4 4 1
h hF F
hF F
2 1
19.58246 ( 19.358622)0.25 19.58246
4 1F
2 1
19.58246 19.3586220.25 19.58246
4 1F
12 | P a g e Richardson's Extrapolation
2
0.223840.25 19.58246
3F
2 0.25 19.58246 ( 0.07461)F
2 0.25 19.58246 0.07461F
2 0.25 19.65707F -------------------------------------------------------------exp(6)
Step 3:- at j=1 and step size h=0.125
1 1
2 1
1 8 4
8 8 4 1j
h hF F
hF F
for j=1 and h=1/8=0.125 18
hF
=-19.63120
1 1
2 1 1
8 40.125
8 4 1
h hF F
hF F
2
19.63120 19.582460.125 19.63120
4 1F
2
0.048740.125 19.63120
3F
2 0.125 19.63120 ( 0.01625)F
2 0.125 19.63120 0.01625F
2 0.125 19.64745F ------------------------------------------------------------exp(7)
13 | P a g e Richardson's Extrapolation
4.1.1.3. Third Order F_3's
From equation 7 above 1
( )2
( )2 4 1
j j
j j j
hF F h
hF h F
1, 2,3,...j we have
1 1
2 1
( )4 2
( )4 4 1
j j
j j j
h hF F
hF h F
Step 1:- at j=2 and step size h=0.25
24
hF
-19.65707 and 2 ( )2
hF -19.79904
2 2
3 2 2
( )4 2
( )4 4 1
h hF F
hF h F
2 2
3 2 2
4 2
4 4 4 1
h hF F
h hF F
3 2
1 19.65707 ( 19.79904)19.65707
4 4 1F
3
19.65707 19.799040.25 19.65707
16 1F
3
0.141970.25 19.65707
15F
3 0.25 19.65707 0.00946F
3 0.25 19.64761F ------------------------------------------------------------exp(8)
Step 2:- at j=2 and step size h=0.125
2 2
3 2 2
8 4
8 8 4 1
h hF F
h hF F
2 2
3 2 2
1 8 4
8 8 4 1
h hF F
hF F
14 | P a g e Richardson's Extrapolation
3
1 19.64745 ( 19.65707)19.64745
8 16 1F
3
19.64745 19.657070.125 19.64745
15F
3
0.009620.125 19.64745
15F
3 0.125 19.64745 0.00064F
3 0.125 -19.646808F ------------------------------------------------------------exp(9)
Step 4:- at j=3 and step size h=0.125
3 3
3 1 3 3
8 4
8 8 4 1
h hF F
h hF F
3 3
4 3 3
8 4
8 8 4 1
h hF F
h hF F
4
1 19.64681 ( 19.64761)19.64681
8 64 1F
4
19.64681 19.647610.125 19.64681
63F
4
0.00080.125 19.64681
63F
4 0.125 19.64681 0.00001F
4 0.125 19.64680F ------------------------------------------------------------exp(10)
15 | P a g e Richardson's Extrapolation
4.1.2. Analysis on Problem one
Here we have done by hand calculation and we have got the following solutions that
shows from exp (1) to exp (10)
H F_1's F_2's F_3's F_4's
1 -18.03737
0.5 -19.35862 -19.79903
0.25 -19.58246 -19.65707 -19.64761
0.125 -19.63120 -19.64745 -19.646808 -19.64680
This result from the given table is the same, let's find analytically the exact derivative
value of the function
3( ) cos( ),f x x x at the point of x=2.3
3 2 3( cos( )) 3* cos( ) ( sin( ))df dy
x x x x x xdx dx
at x=2.3
2 3'(2.3) 3*(2.3) cos(2.3) 2.3 ( sin(2.3))f = -19.64680
The exact derivative value of the function at the point x=2.3. is equal to -19.64680
Now from the table and the exact value we can deduce that as the order increase, the error
becomes near zero (NOT EQUAL) and we have good numerical approximation. At the
fourth order we have almost the same result as of the exact value
16 | P a g e Richardson's Extrapolation
4.1.3. PART II: - Computer Program using MATLAB
4.1.3.1. Algorithm
Step 1:- Set the number of step sizes n
Step 2:- set h(i) as h/2^-(i-1), where i=1 to n
Step 3:-Set F (1,n) for the first order values
Step 4:- evaluate for j--> to n,
F(1,j)=((x+h(j))3cos(x+h(j)) - ( x-h(j))3cos(x-h(j))) /2*h(j)
Step 5:- Calculate for the second, third and fourth order, i=1,..,n
F(i+1,j)=F(i,j)+(F(i,j)-F(i,j-1))/4j-1
Step 6: Get the result and plot
4.1.3.2. MATLAB Program Code
Richardson's Extrapolation using Centered formula for first derivative MATLAB Program
function RichardSonExtraP() % %================================================================== % % This Program is Richardson's' Extrapolation for approximating % % the first derivative % % Written By Abebe Alemu, % % ID GSR/3003/08 % % Addis Ababa University, Faculty of Natural Science % % Computational Science Department % % Graduate Program, -------------- Dated on July 2016 % % ===================================================================== format short; %==============Definition ================ h=zeros(50); h1=zeros(50); h2=zeros(50); h3=zeros(50); F1=zeros(50,50); F2=zeros(50,50); A1=zeros(10); A2=zeros(10); A3=zeros(10); %======Enter Input size from key board ============= fprintf('Please Enter the number of Step sizes n \n n='); n=input(''); A=zeros(n,n); % Assining A1=zeros(n); A2=zeros(n); A3=zeros(n); h=zeros(n);
17 | P a g e Richardson's Extrapolation
h1=zeros(n); h2=zeros(n); h3=zeros(n); x=2.3;% ------------Reference point %===========define Step size ============================================== for i=1:n h(i)=2^-(i-1); % Calculating the step size h end %============End ========================================================== %========================================================================== % Richardson's Extrapolation of first order using centered formula for f'(x) %========================================================================== for j=1:n h(j); F1(1,j)=(((x+h(j))^3)*(cos(x+h(j)))-((x-h(j)))^3*cos(x-h(j)))/(2*h(j)); A(j,1)= F1(1,j); A1(j)=A(j,1); h1(j)=h(j); end % % ---- Second order -------------------------------- for k=2:n F2(k,2)=F1(1,k)+((F1(1,k)-F1(1,k-1))/((4^1)-1)); A(k,2)= F2(k,2); A2(k)=A(k,2); h2(k)=h(k); end % % ------------Third, fourth up to n order ----------------- for m=3:n for k=2:m-1 F2(m,k+1)=F2(m,k)+((F2(m,k)-F2(m-1,k))/((4^k)-1)); A(m,k+1)=F2(m,k+1); A3(k)=A(m,k+1); h3(k)=h(k); end end %======================Dispaly====================================== % Display the result of first derivative value of f(x) at x=1.25 % numerically approximating using Richardson extrapolation disp(' f(x)=(x^3)*cos(x), its first derivative approximate value at x=1.25'); disp('==========================================================='); disp(' No h F_1s | F_2s | F_3s | F_4s |' ); disp('==========================================================='); for i=1:n msg1=sprintf('%0.0f %0.4f %0.6f %0.6f %0.6f %0.6f ',... i, h(i), A(i,1), A(i,2), A(i,3), A(i,4) ); disp([' ',msg1,' ']); end % %===================================================================
18 | P a g e Richardson's Extrapolation
% % The diagram for n step size and its respective value of f'(x) % %=================================================================== figure; % plot on the same figure windows in to four sub plots %--------------- First order plot----------------------------------- subplot(2,2,1) plot(h1,A1,'--rs'); legend('First Order'); axis([0.0 1.0 -20.0 -17.0]); ylabel('f''(x)'); xlabel('Step size h(n)'); title('First Order Richardson''s Extrapolation using Centered Formula'); %------------- Second order plot------------------------------------ subplot (2,2,2); plot(h2,A2,'*'); legend('Second order'); axis([0.0 1.0 -20.0 -17.0]); ylabel('f''(x)'); xlabel('Step size h(n)'); title('Second Order Richardson''s Extrapolation using Centered Formula'); %--------------Third order plot------------------------------------- subplot(2,2,3); plot(h3,A3,'d'); legend('Third Order'); axis([0.0 1.0 -20.0 -17.0]); ylabel('f''(x)'); xlabel('Step size h(n)'); title('Third Order Richardson''s Extrapolation using Centered Formula'); %----------------- on this quadrant I try to show all three plots------ subplot(2,2,4); plot(h1,A1,'--rs'); hold on; plot(h2,A2,'*'); hold on; plot(h3,A3,'d'); hold off; lgnd=legend('Richardson''s Extrapolation using Centered Formula'); axis([0.0 1.0 -20.0 -17.0]); ylabel('f''(x)'); xlabel('Step size h(n)'); title(lgnd,' Title'); % ----------------All in one new figure windows --------------- figure plot(h1,A1,'--rs'); hold on; plot(h2,A2,'*'); hold on; plot(h3,A3,'d');
19 | P a g e Richardson's Extrapolation
hold off; lgnd=legend('Richardson''s Extrapolation using Centered Formula'); axis([0.0 1.0 -20.0 -17.0]); ylabel('f''(x)'); xlabel('Step size h(n)'); title(lgnd,'Title') % % ------------------------END of PROGRAM -------------------- end
4.1.3.3. MATLAB Program Out put
Please Enter the number of Step sizes n
n=4
f(x)=(x^3)*cos(x), its first derivative approximate value at x=1.25
=============================================================
No h F_1s | F_2s | F_3s | F_4s |
=============================================================
1 1.0000 -18.037378 0.000000 0.000000 0.000000
2 0.5000 -19.358622 -19.799037 0.000000 0.000000
3 0.2500 -19.582460 -19.657073 -19.647608 0.000000
4 0.1250 -19.631203 -19.647450 -19.646809 -19.646796
>>
20 | P a g e Richardson's Extrapolation
4.1.3.4. Richardson's Extrapolation step size h vs first order derivative Plot Out
put
21 | P a g e Richardson's Extrapolation
Plot for Richardson extrapolation with for first order derivatives
22 | P a g e Richardson's Extrapolation
4.2. Richardson's' Extrapolation using centered formula for Second Derivatives
4.2.1. PART I:- Working by Hand
From Equation 4 above we have for second derivatives
1 2
( ) 2 ( ) ( )f x h f x f x hF
h
3( ) cos( )f x x x with x=2.3
4.2.1.1. First Order F_1's
Step 1:- at step size h=1
1 2
(2.3 1) 2 (1) (2.3 1)
1
f f fF
3 3 3
1 2
3.3 cos(3.3) 2(2.3 cos(2.3)) 1.3 cos(1.3)
1F
1 2
35.937 cos(3.3) 2(12.167 cos(2.3)) 2.197 cos(1.3)
1F
1 2
35.48706049 2( 8.10650351) 0.58769493
1F
1 2
35.48706049 16.21316070 0.58769493
1F
1
18.68620486
1F
1 18.68620486F
Step 2:- at step size h=0.5
1 2
( ) 2 ( ) ( )f x h f x f x hF
h
1 2
(2.3 0.5) 2 (2.3) (2.3 0.5)
0.5
f f fF
1 2
(2.8) 2 (2.3) (1.8)
0.5
f f fF
3 3 3
1 2
2.8 cos(2.8) 2(2.3 cos(2.8)) 1.8 cos(1.8)
0.5F
1
21.952cos(2.8) 2(12.167 cos(2.3)) 5.832cos(1.8)
0.25F
1
20.68366482 2( 8.10658035) ( 1.32504262)
0.25F
23 | P a g e Richardson's Extrapolation
1
20.68366482 16.2131607 1.32504262
0.25F
1
5.79554674
0.25F
1 23.18218696F
Step 3:- at step size h=0.25
1 2
( ) 2 ( ) ( )f x h f x f x hF
h
1 2
(2.3 0.25) 2 (2.3) (2.3 0.25)
0.25
f f fF
3 3 3
1 2
2.55 cos(2.55) 2(2.3 cos(2.3)) 2.05 cos(2.05)
0.25F
1 2
16.581375*cos(2.55) 2(12.167cos(2.3)) 8.615125*cos(2.05)
0.25F
1 2
13.76342894 2( 8.10658035) 3.97219887
0.25F
1
13.76342894 16.2131607 3.97219887
0.0625F
1
1.52246711
0.0625F
1 24.35947376F
Step 4:- At step size h=0.125
1 2
( ) 2 ( ) ( )f x h f x f x hF
h
h=1/8=0.125
1 2
(2.3 0.125) 2 (2.3) (2.3 0.125)
0.125
f f fF
1 2
(2.425) 2 (2.3) (2.175)
0.125
f f fF
3 3 3
1 2
2.425 cos(2.425) 2(2.3 cos(2.3)) (2.175 cos(2.175))
0.125F
1 2
14.260515625cos(2.425) 2(12.167 cos(2.3)) (10.289109375cos(2.175))
0.125F
24 | P a g e Richardson's Extrapolation
1
10.75311449 2( 8.10658035) ( 5.84531419)
0.015625F
1
10.75311449 16.2131607 5.84531419
0.015625F
1
0.38526798
0.015625F
1 24.65715072F
4.2.1.2. Second Order F_2's
12
hF
=-23.18218696 and 1F h =-18.68620486
Step 1:- At step size h=0.5
1 1
1 1 1
( )2
( )2 4 1j
hF F h
hF h F
2 1
23.18218696 ( 18.68620486)( ) 23.18218696
4 1F h
2
23.18218696 18.68620486( ) 23.18218696
4 1F h
2
4.4959821( ) 23.18218696
3F h
2 ( ) 23.18218696 ( 1.4986607)F h
2 ( ) 23.18218696 1.4986607F h
2 ( ) 24.68084766F h
Step 2:- At step size h=0.25
1( )2
hF -23.18218696 1( )
4
hF -24.35947376
25 | P a g e Richardson's Extrapolation
1 1
2 1 1
4 2
4 4 4 1
h hF F
h hF F
2 1
24.35947376 ( 23.18218696)24.35947376
4 4 1
hF
2
24.35947376 23.1821869624.35947376
4 4 1
hF
2
1.177286824.35947376
4 3
hF
2 24.35947376 ( 0.39242894)4
hF
2 24.35947376 0.499553574
hF
2 24.751902694
hF
Step 3:- At step size h=0.125
1( )4
hF -24.35947376 and 1( )
8
hF -24.65715072
1 1
2 1 1
8 4
8 8 4 1
h hF F
h hF F
2 1
24.65715072 ( 24.35947376)24.65715072
8 4 1
hF
2 1
24.65715072 24.3594737624.65715072
8 4 1
hF
2
0.2976769624.65715072
8 3
hF
2 24.65715072 ( 0.09922565)8
hF
2 24.756376378
hF
26 | P a g e Richardson's Extrapolation
4.2.1.3. Third Order F_3's at j=2
Step 1:- At step size of h=0.25
2 ( )2
hF -24.68084766 and 2 ( )
4
hF -24.75190269
2 2
3 2 2
4 2
4 4 4 1
h hF F
h hF F
3 2
24.75190269 ( 24.68084766)24.75190269
4 4 1
hF
3
24.75190269 24.6808476624.75190269
4 16 1
hF
3
0.0710550324.75190269
4 15
hF
3 24.756639694
hF
Step 2:- At step size h=0.125
2 ( )4
hF -24.75190269 and 2 ( )
8
hF -24.75637637
2 2
3 2 2
8 4
8 8 4 1
h hF F
h hF F
3 2
24.75637637 ( 24.75190269)24.75637637
8 4 1
hF
3 2
24.75637637 24.7519026924.75637637
8 4 1
hF
3
0.0044736824.75637637
8 16 1
hF
3
0.0044736824.75637637
8 15
hF
3 24.75637637 ( 0.00029825)8
hF
27 | P a g e Richardson's Extrapolation
3 24.756674628
hF
4.2.1.4. Fourth Order F_4's
at j=3
3( )4
hF 24.75663969 and 3( )
8
hF -24.75667462
3 3
3 1 3
( )8 4
( )8 8 4 1j
h hF F
h hF F
for j=3 and h=1/8=0.125
3 2
4 3 3
8 4
8 8 4 1
h hF F
h hF F
4 3
24.75667462 ( 24.75663969)24.75667462
8 4 1
hF
4
24.75667462 24.7566396924.75667462
8 64 1
hF
4
0.0000349324.75667462
8 63
hF
4 24.75667462 ( 0.00000055)8
hF
4 24.75667462 0.000000558
hF
4 24.756675178
hF
28 | P a g e Richardson's Extrapolation
4.2.2. PART II: - Computer Program using MATLAB
4.2.2.1. Algorithm
Step 1:- Set the number of step sizes n
Step 2:- set h(i) as h/2^-(i-1), where i=1 to n
Step 3:-Set F (1,n) for the first order values
Step 4:- evaluate for j--> to n,
F(1,j)=((x+h(j))3cos(x+h(j)) -2*(x)3*cos(x)+( x-h(j))3cos(x-h(j))) /2*h(j)
Step 5:- Calculate for the second, third and fourth order, i=1,..,n
F(i+1,j)=F(i,j)+(F(i,j)-F(i,j-1))/4j-1
Step 6: Get the result and plot
4.2.2.2. Computer MATLAB Program function SecRichardSonExtraP() % %================================================================== % % This Program is Extrapolation for approximating the first derivative % % Written By Abebe Alemu, % % ID GSR/3003/08 % % Addis Ababa University, Faculty of Natural Science % % Computational Science Department % % Graduate Program, -------------- Dated on July 2016 % % ===================================================================== format shorte; %==============Definition ================ h=zeros(50); h1=zeros(50); h2=zeros(50); h3=zeros(50); F1=zeros(50,50); F2=zeros(50,50); A1=zeros(10); A2=zeros(10); A3=zeros(10); n=10; %======Enter Input size from key board ============= fprintf('Please Enter the number of Step sizes n \n n='); n=input(''); A1=zeros(n); A2=zeros(n); A3=zeros(n); h=zeros(n); h1=zeros(n); h2=zeros(n); h3=zeros(n); x=2.3;% ------------Reference point
29 | P a g e Richardson's Extrapolation
%===========define Step size ============================================== for i=1:n h(i)=2^-(i-1); end A=zeros(n,n); %============End ========================================================== %====================================================================== % Richardson's Extrapolations for second order derivatives %====================================================================== for j=1:n h(j); F1(1,j)=(((x+h(j))^3)*(cos(x+h(j)))-2*x^3*cos(x)+((x-h(j)))^3*cos(x-h(j)))/(h(j)^2); A(j,1)= F1(1,j); A1(j)=A(j,1); h1(j)=h(j); end for k=2:n % ---- Second order F2(k,2)=F1(1,k)+((F1(1,k)-F1(1,k-1))/((4^1)-1)); A(k,2)= F2(k,2); A2(k)=A(k,2); h2(k)=h(k); end for m=3:n % Third to n th order for k=2:m-1 F2(m,k+1)=F2(m,k)+((F2(m,k)-F2(m-1,k))/((4^k)-1)); A(m,k+1)=F2(m,k+1); A3(k)=A(m,k+1); h3(k)=h(k); end end %=======================End ======================================== %======================Dispaly====================================== % Display the approximate first derivative value of f(x) at x=1.25 disp(' f(x)=x^3cos(x), its first derivative approximate value at x=1.25'); disp('=============================================================='); disp(' No h F_1s | F_2s | F_3s | F_4s |' ); disp('=============================================================='); for i=1:n msg1=sprintf('%0.0f %0.4f %0.8f %0.8f %0.8f %0.8f ',... i, h(i), A(i,1), A(i,2), A(i,3), A(i,4) ); disp([' ',msg1,' ']); end % %=================================================================== % % Plot % %=================================================================== figure; %--------------- First order plot------------------------------------- subplot(2,2,1) plot(h1,A1,'--rs'); title('Richardson''s Extrapolation First Order Derivatives'); xlabel('Step Size h'); legend('First Order'); ylabel('f''(x)');
30 | P a g e Richardson's Extrapolation
axis([0.0 1.0 -25.0 -17.0]); %------------- Second order plot--------------------------------------- subplot (2,2,2); plot(h2,A2,'*'); title('Richardson''s Extrapolation Second Order Derivatives'); xlabel('Step Size h'); legend('Second Order'); axis([0.0 1.0 -25.0 -17.0]); %--------------Third order plot-------------------------------------- subplot(2,2,3); plot(h3,A3,'d'); title('Richardson''s Extrapolation Third Order Derivatives'); xlabel('Step Size h'); legend('Third Order'); axis([0.0 1.0 -25.0 -17.0]); subplot(2,2,4); plot(h1,A1,'--rs',h2,A2,'*',h3,A3,'d'); lgnd=legend('Richardson''s Extrapolation '); ylabel('f''(x)'); xlabel('Step size h(n)'); title(lgnd,' Title'); axis([0.0 1.0 -25.0 -17.0]); % % ------------------------END of PROGRAM -------------------- end
4.2.2.3. Computer MATLAB Output
Please Enter the number of Step sizes n
n=6
f(x)=x^3cos(x), its first derivative approximate value at x=1.25
============================================================
No h F_1s | F_2s | F_3s | F_4s |
============================================================
1 1.0000 -18.68620486 0.00000000 0.00000000 0.00000000
2 0.5000 -23.18218695 -24.68084764 0.00000000 0.00000000
3 0.2500 -24.35947370 -24.75190262 -24.75663962 0.00000000
4 0.1250 -24.65717631 -24.75641052 -24.75671104 -24.75671218
5 0.0625 -24.73181406 -24.75669331 -24.75671216 -24.75671218
6 0.0313 -24.75048676 -24.75671100 -24.75671218 -24.75671218
>>
31 | P a g e Richardson's Extrapolation
4.2.2.4. Richardson's extrapolation plot step size for second derivatives
32 | P a g e Richardson's Extrapolation
5. Problem definition Two Given f(x)=exp(x2)cos(3x), reference point x=1.25
Use Richardson's Extrapolation and the central difference results of the first derivatives and
second derivatives,
The exact value is given as which is equal to exact= -1.606374738, To check this is true, let's find analytically by finding the first derivatives of the function f( f(x)=exp(x2)cos(3x)
2
2 2
2 2
( ) (exp( ) cos(3 )) '
exp( )*2 *cos(3 ) exp( )( 3*sin(3 ))
'(1.25) exp(1.25 )*2(1.25)*cos(3*1.25) exp(1.25 )*3*sin(3*1.25)
'(1.25) -1.606374738
dfx x x
dx
x x x x x
f
f
Yes analytically we have '(1.25) -1.606374738f
Solution
5.1. Richardson's Extrapolation first derivatives for even power Order of h
5.1.1. PART I :- working by hand
20 00
0 00
( ) ( )( ) ( )
2
( ) ( )'( )
2
f x h f x hdfx O h
dx h
f x h f x hf x
h
, ----------------------------------------------------eq(1)
Find the truncation error O(h2) we use 20( ) '( )O h exact f x ,-------------------------eq(2)
Now let's find first order derivatives, with step size h=1
33 | P a g e Richardson's Extrapolation
5.1.1.1. Second order First derivative
Step 1:- Step Size h=0.4,
1
2 2
2
2
2
(2.3 1) (2.3 1)( )
2(1)
(3.3) (1.3)(1)
2
(3.3) cos(3.3) (1.3) cos(1.3)
2
(35.0*0.2353814) (2.05957572)( 0.8300535)
2
6.61458451
(2)
( ) 1.606374738 ( )
( ) 1.606374738 6.61458451
( )
f fF h
f fF
From eq
O h F h
O h
O h
8.220959248
Step 2:- At Step Size h/2=0.2
2 2
( ) 0.2
(1)
(1.25 0.2) (1.25 0.2)( )
2(0.2)
(1.45) (1.05)(0.2)
0.4
exp(1.45 )cos(3*1.45) exp(1.05 )cos(3*1.05)(0.2)
0.4
8.18661088*( 0.35450907) (3.01168583* 0.99996466)
0.4
0.2733789
step size h is
From eq
f fF h
f fF
F
2
2
2
675
(2)
( ) 1.606374738 ( )
( ) 0.2
( ) 1.606374738 0.2733789675
( ) 1.8797537055
From eq
O h F h
a step size h is
O h
O h
34 | P a g e Richardson's Extrapolation
Step 3:- At Step Size h/4= 0.1
2 2
, ( ) 0.1
(1)
(1.25 0.1) (1.25 0.1)( )
2(0.1)
(1.35) (1.15)(0.1)
0.2
exp(1.35 )cos(3*1.35) exp(1.15 )cos(3*1.15)(0.1)
0.2
6.1873074*( 0.61500238) (3.75279164*( 0.95281821)
0.2
1.
when a step size h is
From eq
f fF h
f fF
F
14740285
2
2
2
(2)
( ) 1.606374738 ( )
, ( ) 0.1
( ) 1.606374738 1.14740285
( ) 0.45897189
From eq
O h F h
when a step size h is
O h
O h
Step 4:- At step size h/8=0.05
2 2
2
(1)
(1.25 0.05) (1.25 0.05)( )
2(0.05)
(1.3) (1.2)(0.05)
0.1
exp(1.3 ) cos(3*1.3) exp(1.2 )cos(3*1.2)(0.05)
0.1
5.41948071*( 0.725932304) (4.22069582*( 0.89675842)
0.1
1.49231606
(2)
(
From eq
f fF h
f fF
F
From eq
O h
2
2
) 1.606374738 ( )
( ) 1.606374738 1.49231606
( ) 0.11405864
F h
O h
O h
35 | P a g e Richardson's Extrapolation
Step 5 :- At Step Size h/16=0.025
2 2
(1)
(1.25 0.025) (1.25 0.025)( )
2(0.025)
(1.(1.275) (1.225)(0.025)
0.05
exp((1.275) ) cos(3*1.275) exp((1.225) )cos(3*1.225)(0.025)
0.05
5.08159404*( 0.77542569) (4.484491*( 0.86107954)
0.05
From eq
f fF h
f fF
F
1.5779022
2
2
2
(2)
( ) 1.606374738 ( )
( ) 1.606374738 1.5779022
( ) 0.02847254
From eq
O h F h
O h
O h
Step 6:- At Step Size h/32=0.0125
2 2
(1)
(1.25 0.0125) (1.25 0.0125)( )
2(0.0125)
(1.2652) (1.2375)(0.0125)
0.05
exp((1.2625) ) cos(3*1.2625) exp((1.2375) ) cos(3*1.2375)(0.0125)
0.05
4.92294166*( 0.79855394) (4.6246757*( 0.84141
From eq
f fF h
f fF
F
2
2
2
0995)
0.025
1.5992592
(2)
( ) 1.606374738 ( )
( ) 1.606374738 1.5992592
( ) 0.00711554
From eq
O h F h
O h
O h
36 | P a g e Richardson's Extrapolation
Step 7:- At Step Size h/64=0.00625
2 2
(1)
(1.25 0.0125) (1.25 0.0125)( )
2(0.00625)
(1.25652) (1.24375)(0.00625)
0.0125
exp((1.25625) )cos(3*1.2625) exp((1.24375) ) cos(3*1.24375)(0.00625)
0.0125
4.846050593*( 0.80969898) (4.6969
From eq
f fF h
f fF
F
2
2
2
53291*( 0.83113127)
0.0125
1.6045976
(2)
( ) 1.606374738 ( )
( ) 1.606374738 1.6045976
( ) 0.0001777138
From eq
O h F h
O h
O h
5.1.1.2. Fourth Order first derivative
1
( ) ( )2( ) ( ) ( ), 1, 2,3,
2 4 1
j j
j j
hF F h
hF h Fj j
-----------------------------------eq(3)
Step 1:- At step size h/2=0.2
1 1 1
2
2
(0.2) (0.4)(0.2) (0.2)
4 1
0.27337907 6.6145854401(0.2) 0.27337907+( )
3
(0.2) -1.8403563833
F FF F
F
F
4
4
4
4
(2) ( )
( ) 1.606374738 ( )
( ) 1.60637473 (-1.8403563833)
( ) 0.2339816453
from eq O h
O h F h
O h
O h
37 | P a g e Richardson's Extrapolation
Step 2:- At Step Size h/4=0.1
1 1 1
2
2
(3)
(0.1) (0.2)(0.1) (0.1)
4 1
-1.1474026294 0.2733790725(0.1) -1.1474026294+( )
3
(0.1) -1.6209965300
From eq
F FF F
F
F
4
4
4
4
(2) ( )
( ) 1.606374738 ( )
( ) 1.60637473 (-1.6209965301)
( ) 0.01462179201
from eq O h
O h F h
O h
O h
Step 3:- At Step size h/8=0.05
1 1 1
2
2
(3),
(0.05) (0.1)(0.05) (0.05)
4 1
-1.4923161916+1.1474026294(0.05) -1.4923161916+( )
3
(0.05) -1.6072873807
From eq
F FF F
F
F
4
4
4
4
(2) ( )
( ) 1.606374738 ( )
( ) 1.60637473 (-1.6072873807)
( ) 0.0009126427
from eq O h
O h F h
O h
O h
Step 4:- At Step size h/16=0.025
1 1 1
2
2
(3)
(0.025) (0.05)(0.025) (0.025)
4 1
-1.5779028639+1.4923161916(0.025) -1.5779028639+( )
3
(0.025) -1.6064317547
From eq
F FF F
F
F
38 | P a g e Richardson's Extrapolation
4
4
4
4
(2) ( )
( ) 1.606374738 ( )
( ) 1.606374738 (-1.6064317547)
( ) 0.0000570167
from eq O h
O h F h
O h
O h
Step 5:- At Step size h/32=0.0125
1 1 1
2
2
(3)
(0.0125) (0.025)(0.0125) (0.0125)
4 1
-1.59925944+1.57790286(0.0125) -1.59925944+( )
3
(0.0.125) -1.60637830
From eq
F FF F
F
F
4
4
4
4
(2) ( )
( ) 1.60637473 ( )
( ) 1.60637473 (-1.60637830)
( ) 0.00000356
from eq O h
O h F h
O h
O h
Step6:- At Step size h/64=0.00625
1 1 1
2
2
(3),
(0.00625) (0.0125)(0.00625) (0.00625)
4 1
-1.60459608+1.59925944(0.00625) -1.60459608+( )
3
(0.00625) 1.60637496
From eq
F FF F
F
F
4
4
4
4
(2) ( )
( ) 1.60637473 ( )
( ) 1.60637473 ( 1.60637496)
( ) 0.00000022
from eq O h
O h F h
O h
O h
39 | P a g e Richardson's Extrapolation
5.1.1.3. Sixth Order first derivative
Step 1:- At the step size of h/4=0.1
2 1 2
3
3
(3),
(0.1) (0.2)(0.1) (0.1)
4 1
- 1.62099653-(-1.84035638)(0.1) -1.62099653+( )
15
(0.1) 1.60637253
From eq
F FF F
F
F
6
6
6
6
(2) ( )
( ) 1.606374738 ( )
( ) 1.60637473 ( 1.60637254)
( ) 0.0000022
from eq O h
O h F h
O h
O h
Step 2:- At the step size of h/8=0.05
2 1 2
3
3
(3),
(0.05) (0.1)(0.05) (0.05)
4 1
- 1.60728738-(- 1.62099653)(0.05) -1.60728738+( )
15
(0.05) 1.60637344
From eq
F FF F
F
F
6
6
6
6
(2) ( )
( ) 1.606374738 ( )
( ) 1.60637473 ( 1.60637343)
( ) 0.000001301
from eq O h is
O h F h
O h
O h
Step 3:- At the step size of h/16=0.025
2 1 2
3
3
(3)
(0.025) (0.05)(0.025) (0.025)
4 1
-1.60643175-(-1.60728738)(0.025) -1.60643175+( )
15
(0.025) 1.60637471
From eq
F FF F
F
F
40 | P a g e Richardson's Extrapolation
6
6
6
6
(2) ( )
( ) 1.60637473 ( )
( ) 1.60637473 ( 1.60637471)
( ) 0.00000003
from eq O h
O h F h
O h
O h
Step 4:- At the step size of h/32=0.0125
2 1 2
3
3
(3),
(0.0125) (0.025)(0.0125) (0.025)
4 1
-1.60637830-(-1.60643175)(0.0125) -1.60637830+( )
15
(0.0125) 1.60637474
From eq
F FF F
F
F
6
6
6
6
(2) ( )
( ) 1.60637473 ( )
( ) 1.60637473 ( 1.60637471)
( ) 0.0000000004
from eq O h
O h F h
O h
O h
Step 5:- At the step size of h/64=0.00625
2 1 2
3
3
(3),
(0.00625) (0.0125)(0.00625) (0.025)
4 1
-1.60637496-(-1.60637830)(0.00625) -1.60637496+( )
15
(0.00625) 1.606374738
From eq
F FF F
F
F
6
6
6
6
(2) ( )
( ) 1.606374738 ( )
( ) 1.60637473 ( 1.60637471)
( ) 0.000000000009
from eq O h
O h F h
O h
O h
41 | P a g e Richardson's Extrapolation
5.1.1.4. Eighth Order first derivative
Step 1:- At step size h/8=0.05
3 1 3
4
4
(3),
(0.05) (0.1)(0.05) (0.05)
4 1
-1.6063734374-(-1.6063725398)(0.05) -1.60637343+( )
63
(0.05) 1.6063734516
From eq
F FF F
F
F
8
8
8
8
(2) ( )
( ) 1.606374738 ( )
( ) 1.606374738 ( 1.60637345167)
( ) 0.00000128632
from eq O h
O h F h
O h
O h
Step 2:- At step size h/16=0.025
3 1 3
4
4
(3),
(0.025) (0.05)(0.025) (0.025)
4 1
-1.606374713-(-1.60637343742)(0.025) -1.6063747129+( )
63
(0.025) 1.6037473324
From eq
F FF F
F
F
8
8
8
8
(2) ( )
( ) 1.606374738 ( )
( ) 1.606374738 ( 1.60637345167)
( ) 0.0000000047
from eq O h
O h F h
O h
O h
Step 3:- At step size h/32=0.0125
3 1 3
4
4
(3)
(0.0125) (0.025)(0.0125) (0.0125)
4 1
-1.6063747376-(-1.6063747)(0.0125) -1.6063747376+( )
63
(0.0125) 1.606374737995
From eq
F FF F
F
F
42 | P a g e Richardson's Extrapolation
8
8
8
8
(2) ( )
( ) 1.606374738 ( )
( ) 1.606374738 ( 1.60637345167)
( ) 0.00000000000479299
from eq O h
O h F h
O h
O h
5.1.2. PART II: - Computer Program using MATLAB
5.1.2.1. Algorithm
Step 1:- Set the number of step sizes n
Step 2:- set h(i) as h/2^-(i-1), where i=1 to n
Step 3:-Set F (1,n) for the Second order values
Step 4:- evaluate for j--> to n,
F(1,j)=(exp(x+h(j))2cos(3*(x+h(j)) )-( exp( x-h(j))2 cos(3*(x-h(j)))) /2*h(j)
Step 5:- Calculate for the foruth, sixth and eighth order, as well i=1,..,n
F(i+1,j)=F(i,j)+(F(i,j)-F(i,j-1))/4j-1
Step 6: Get the result and plot
5.1.2.2. Computer MATLAB Program function OrderH() % %================================================================== % % This Program is Richardson's Extrapolation and central difference formula % % for the first derivative % % Written By Abebe Alemu, % % ID GSR/3003/08 % % Addis Ababa University, Faculty of Natural Science % % Computational Science Department % % Graduate Program, -------------- Dated on July 2016 % % ===================================================================== format shorte; %==============Definition ================ h=zeros(50); h1=zeros(50); h2=zeros(50); e=zeros(50); e2=zeros(50); e3=zeros(50); F1=zeros(50,50); F2=zeros(50,50); x=1.25; % ------------Reference point %======Enter Input size from key board ============= fprintf('Please Enter the number of Step sizes n \n n='); n=input('');
43 | P a g e Richardson's Extrapolation
% % ============================================ % % f(x)=exp(x^2)cos(3x) given function % % ================================================ % Analytical Exact value of the first derivative of the function at x=1.25 exact=-1.606374738; %===========define Step size ============= for i=1:n h(i)=0.4*(2^-(i-1)); end %A=zeros(n,n); Oh2=zeros(n,n); %============End ============================= %=========================================== % Richardson's Extrapolation, centered difference for first derivative %============================================== for j=1:n h(j); F1(1,j)=(((exp((x+h(j))^2))*(cos(3*(x+h(j)))))- ... ((exp((x-h(j))^2))*cos(3*(x-h(j)))))/(2*h(j)); Oh2(j,1)=exact-F1(1,j); e(j)=Oh2(j,1); end for k=2:n F2(k,2)=F1(1,k)+((F1(1,k)-F1(1,k-1))/((4^1)-1)); Oh2(k,2)= exact-F2(k,2); e2(k)=Oh2(k,2); end for m=3:n for k=3:m F2(m,k)=F2(m,k-1)+((F2(m,k-1)-F2(m-1,k-1))/((4^(k-1))-1)); Oh2(m,k)=exact-F2(m,k); e3(k)=Oh2(m,k); end end % %=============================End ============================= % %===========================Display============================ disp('=============================================================='); disp(' No h O(h^2) O(h^4) O(h^6) O(h^8) '); disp('=============================================================='); for i=1:n % 0.10f ten digit precision msg1=sprintf('%0.0f %0.4f %0.10f %0.10f %0.10f %0.10f ', ... i, h(i), Oh2(i,1), Oh2(i,2), Oh2(i,3), Oh2(i,4) ); disp([' ',msg1,' ']); end %========================================================================= for i=2:n h1(i)=h(i); end for j=3:n h2(j)=h(j); end % %=======================================================
44 | P a g e Richardson's Extrapolation
% % Plotting the graph using step size h and the error % %======================================================= figure; subplot(2,2,1)% ----- Plot the first order in the first quadrant plot(h,e,'--rs') title('Richardson''s Extrapolation Second Derivatives'); xlabel('Step Size h'); legend('Secodn order O(h^2)'); ylabel('f''(x)'); axis([0.0 0.5 -10.0 0.0]); grid on; subplot (2,2,2); % ----- Plot the second order in the second quadrant plot(h1,e2,'*'); title('Richardson''s Extrapolation Second Derivatives'); xlabel('Step Size h'); legend('Secodn order O(h^4)'); ylabel('f''(x)'); axis([0.0 0.3 0.0 0.25]); grid on; subplot(2,2,3); % -----Plot the third order on the third quadrant plot(h2,e3,'--rs'); title('Richardson''s Extrapolation Second Derivatives'); xlabel('Step Size h'); legend('Second order O(h^6)'); ylabel('f''(x)'); axis([0.0 0.510 -0.10 0.0]); grid on; subplot(2,2,4); % -----Plot the three figures in the same quadrant plot(h,e) hold on; plot(h1,e2,'*'); hold on; plot(h2,e3); title('Richardson''s Extrapolation Secodn Derivatives'); xlabel('Step Size h'); legend('Secodn order O(h^2)'); ylabel('f''(x)'); axis([0.0 0.5 -10.0 0.0]); grid on; end
45 | P a g e Richardson's Extrapolation
5.1.2.3. Computer MATLAB Output
Please Enter the number of Step sizes n
n=6
===========================================================
No h O(h^2) O(h^4) O(h^6) O(h^8)
===========================================================
1 0.4000 -8.2209601781 0.0000000000 0.0000000000 0.0000000000
2 0.2000 -1.8797538106 0.2339816453 0.0000000000 0.0000000000
3 0.1000 -0.4589721086 0.0146217921 -0.0000021981 0.0000000000
4 0.0500 -0.1140585463 0.0009126411 -0.0000013023 -0.0000012881
5 0.0250 -0.0284718740 0.0000570167 -0.0000000249 -0.0000000046
6 0.0125 -0.0071152961 0.0000035632 -0.0000000004 0.0000000000
>>
5.1.2.4. Computer MATLAB Plot Ext.Polation for first derivatives
46 | P a g e Richardson's Extrapolation
5.2. Richardson's Extrapolation Using three point Second Derivatives
Given 2
20 0 002 2
( ) 2 ( ) ( )( ) ( )
f x h f x f x hfx o h
x h
where 0x =1.25, and exact analytical
value is given 43.8375005482.
'' 0 0 00 2
( ) 2 ( ) ( )( )
f x h f x f x hf x
h
-----------------------------------------eq(1)
From above solution A, we have got the first derivative of the function
2( ) exp( ) cos(3 )f x x x , we can find easily the second derivatives annalistically
2
2 2
2 2 2 2
2 2
( ) (exp( ) cos(3 )) '
'( ) exp( )*2 *cos(3 ) exp( )( 3*sin(3 ))
''( ) [exp( )*4 *cos(3 ) exp( )*2*cos(3 ) exp( )*2 *( sin(3 ))]
[exp( )*2 *( 3*sin(3 )) exp( )( 9*cos(3 ))]
dfx x x
dx
f x x x x x x
f x x x x x x x x x
x x x x x
Substituting the value of x=1.25 at the expression, and we have got 43.8375005482 this is
exact value analytically; then let's find the relative error by finding in each step size
error of order nth of h is O(hn)=exact - f''(x) --------------------------------eq(2)
Solution
5.2.1. PART I: - working by hand
Reference value 0x =1.25, 2( ) exp( ) cos(3 )f x x x
Step 1:- Order two O(h2), at h=0.4
''
2
(1.25 0.4) 2 (1.25) (1.25 0.4)(1.25)
0.4
f f ff
=
(1.65) 2 (1.25) (0.85)
0.16
f f f
2 2 2'' exp((1.65) ) cos(3*1.65) 2*exp(1.25 )cos(3*1.25) exp((0.85) )cos(3*0.85)(1.25)
0.16f
'' (1.25) 60.6368227893f
from the above equation 2 second order error 2( )o h
2
2
( ) 43.8375005482 60.6368227893
( ) 16.7993222411
o h
o h
47 | P a g e Richardson's Extrapolation
Step 2:- At Step size h=0.2
'' 0 0 02
( ) 2 ( ) ( )( )
f x h f x f x hf x
h
''
2
(1.25 0.2) 2 (1.25) (1.25 0.2)(1.25)
0.2
f f ff
=
(1.45) 2 (1.25) (1.05)
0.04
f f f
2 2 2'' exp((1.45) )cos(3*1.45) 2*exp(1.25 )cos(3*1.25) exp((1.05) ) cos(3*1.05)(1.25)
0.04f
'' (1.25) 47.8883085539f
Find second order error 2( )o h for h/2=0.2 is from eq(2)
2
2
( ) 43.8375005482 47.8883085539
( ) 4.0508080057
o h
o h
Step 3:- at Step size h/4=0.1
''
2
(1.25 0.1) 2 (1.25) (1.25 0.1)(1.25)
0.1
f f ff
=
(1.35) 2 (1.25) (1.15)
0.01
f f f
2 2 2'' exp((1.35) )cos(3*1.35) 2*exp(1.25 )cos(3*1.25) exp((1.15) ) cos(3*1.15)(1.25)
0.04f
'' (1.25) 44.8402524014f
Find second order error 2( )o h at step size 0.1
2
2
( ) 43.8375005482 44.8402524014
( ) 1.0027518532
o h
o h
Step 4:- at Step size h/8=0.05
''
2
(1.25 0.05) 2 (1.25) (1.25 0.05)(1.25)
0.05
f f ff
=
(1.30) 2 (0.05) (1.2)
0.0025
f f f
48 | P a g e Richardson's Extrapolation
2 2 2'' exp((1.30) )cos(3*1.30) 2*exp(1.25 )cos(3*1.25) exp((1.2) ) cos(3*1.2)(1.25)
0.0025f
'' (1.25) 44.0875580582f
Find second order error 2( )o h fro step size 0.05
2
2
( ) 43.8375005482 44.0875580582
( ) 0.2500575100
o h
o h
Step 5:- At Step size h/16=0.025
''
2
(1.25 0.025) 2 (1.25) (1.25 0.025)(1.25)
0.025
f f ff
=(1.275) 2 (1.25) (1.2225)
0.000625
f f f
2 2 2'' exp((1.275) )cos(3*1.275) 2*exp(1.25 )cos(3*1.25) exp((1.2225) )cos(3*1.2225)(1.25)
0.000625f
'' (1.25) 43.8999753936f
Find second order error 2( )o h for step size 0.025
2
2
( ) 43.8375005482 43.8999753936
( ) 0.0624748454
o h
o h
Step 6:- At Step size h/32=0.0125
''
2
(1.25 0.0125) 2 (1.25) (1.25 0.0125)(1.25)
0.0125
f f ff
=(1.2625) 2 (1.25) (1.2375)
0.00015625
f f f
2 2 2'' exp((1.2625) )cos(3*1.2625) 2*exp(1.25 )cos(3*1.25) exp((1.2375) )cos(3*1.2375)(1.25)
0.00015625f
'' (1.25) 43.8531167568f
49 | P a g e Richardson's Extrapolation
Find second order error 2( )o h at step size h/32=0.0125
2
2
( ) 43.8375005482 43.8531167568
( ) 0.0156162386
o h
o h
Generally after working second derivative with three point' using second derivative by
hand we have the following order of errors
h 2( )o h 4( )o h 6( )o h
0.4 -16.7993222411 ##### ####
0.2 -4.0508080057 0.1986967394 ####
0.1 -1.0027518532 0.0132668641 0.0009048724
0.05 -0.2500575100 0.0008406044 0.0000121871
0.025 -0.0624748454 0.0000527095 0.0000001832
0.0125 -0.0156162386 0.0000032970 0.0000000028
5.2.2. PART II: - Computer Program using MATLAB
5.2.2.1. Algorithm
Step 1:- Set the number of step sizes n
Step 2:- set h (i) as h/2^-(i-1), where i=1 to n
Step 3:-Set F (1,n) for the Second order values
Step 4:- evaluate for j--> to n,
F(1,j)=(exp(x+h(j))2cos(3*(x+h(j)) )-2*(exp(x)2*cos(3x)+(exp( x-h(j))2
cos(3*(x-h(j)))) /h(j)2
Step 5:- Calculate for the second, third and fourth order, i=1,..,n
Step 6:- Get the result and plot
5.2.2.2. Computer MATLAB Program function Order2H() % %================================================================== % % This Program is Extrapolation for approximating the first derivative % % Written By Abebe Alemu, % % ID GSR/3003/08 % % Addis Ababa University, Faculty of Natural Science % % Computational Science Department % % Graduate Program, -------------- Dated on July 2016 % % ===================================================================== format short; %==============Defintion ================
50 | P a g e Richardson's Extrapolation
h=zeros(50); F1=zeros(50,50); F2=zeros(50,50); h1=zeros(50); h2=zeros(50); e=zeros(50); e2=zeros(50); e3=zeros(50); %======Enter Input size from key board ============= fprintf('Please Enter the number of Step sizes n \n n='); n=input(''); x=1.25;% ------------Refernce point exact=43.8375005482; %===========Define Step size ============= for i=1:n h(i)=0.4*(2^-(i-1)); h(i); A=zeros(n,n); Oh2=zeros(n,n); %============End ============================= %=========================================== % Calucation %f(x)=exp(x^2)cos(3x) %============================================== for j=1:n h(j); F1(1,j)=((exp((x+h(j))^2)*(cos(3*(x+h(j)))))-(2*(exp(x^2))*cos(3*x))+((exp((x-h(j))^2))*cos(3*(x-h(j)))))/(h(j)^2); Oh2(j,1)=exact-F1(1,j); e(j)=Oh2(j,1); % A(j,1)= F1(1,j); end for k=2:n F2(k,2)=F1(1,k)+((F1(1,k)-F1(1,k-1))/((4^1)-1)); Oh2(k,2)= exact-F2(k,2); e2(k)=Oh2(k,2); end for m=3:n for k=2:m-1 F2(m,k+1)=F2(m,k)+((F2(m,k)-F2(m-1,k))/((4^k)-1)); Oh2(m,k+1)=exact-F2(m,k+1); e3(k)=Oh2(m,k); end end % for i=2:n % h1(i)=h(i); % end % for j=3:n % h2(j)=h(j); % end % %=======================End ==================================== %===============Dispaly=========================== disp('=============================================================='); disp(' F_1s F_2s F_3s F_4s '); disp('=============================================================='); %Oh2(i,j)=Oh2(i,j);
51 | P a g e Richardson's Extrapolation
for i=1:n %for j=1:i %err=Oh2(i,j); msg1=sprintf('%0.0f %0.4f %0.10f %0.10f %0.10f %0.10f ', ... i, h(i), Oh2(i,1), Oh2(i,2), Oh2(i,3), Oh2(i,4) ); disp([' ',msg1,' ']); %end end figure; subplot(2,2,1)% ----- Plot the first order in the first quadrant plot(h,e,'--rs') title('Richardson''s Extrapolation Second Derivatives'); xlabel('Step Size h'); legend('Secodn order O(h^2)'); ylabel('f''(x)'); axis([0.0 0.5 -10.0 0.0]); grid on; subplot (2,2,2); % ----- Plot the second order in the second quadrant plot(h1,e2,'*'); title('Richardson''s Extrapolation Second Derivatives'); xlabel('Step Size h'); legend('Secodn order O(h^4)'); ylabel('f''(x)'); axis([0.0 0.3 0.0 0.25]); grid on; subplot(2,2,3); % -----Plot the third order on the third quadrant plot(h2,e3,'--rs'); title('Richardson''s Extrapolation Second Derivatives'); xlabel('Step Size h'); legend('Second order O(h^6)'); ylabel('f''(x)'); axis([0.0 0.510 -0.10 0.0]); grid on; subplot(2,2,4); % -----Plot the three figures in the same quadrant plot(h,e) hold on; plot(h1,e2,'*'); hold on; plot(h2,e3); title('Richardson''s Extrapolation Secodn Derivatives'); xlabel('Step Size h'); legend('Secodn order O(h^2)'); ylabel('f''(x)'); axis([0.0 0.5 -10.0 0.0]); grid on; %================================================ end
52 | P a g e Richardson's Extrapolation
5.2.2.3. Computer MATLAB Output for second derivatives
=============================================================
No o(h^n) F_1s F_2s F_3s F_4s
=============================================================
1 0.4000 -16.7993222411 0.0000000000 0.0000000000 0.0000000000
2 0.2000 -4.0508080057 0.1986967395 0.0000000000 0.0000000000
3 0.1000 -1.0027518532 0.0132668643 0.0009048726 0.0000000000
4 0.0500 -0.2500575100 0.0008406043 0.0000121870 -0.0000019826
5 0.0250 -0.0624748454 0.0000527095 0.0000001832 -0.0000000073
6 0.0125 -0.0156162386 0.0000032970 0.0000000028 -0.0000000000
>>
5.2.2.4. Computer MATLAB Plot
53 | P a g e Richardson's Extrapolation
6. Observation Recursive difference formulas for derivatives can be obtained by canceling the truncation
error at each order of numerical approximation. This method is called Richardson
extrapolation. It can be used only if the data values are equally spaced with step size h.
1. From Taylors series '' (3) ( )
2 3
'
( ) ( ) ( )( ) ( ) ( ) ( ) ... ( )
2! 3! !( )
( )
nnf a f a f a
f x f a x a x a x an
f ax a
One can deduce that
2. Forward difference formula
' ( ) ( )( )
f x h f xf x
h
for first derivatives
Denote the two-point forward difference approximation as F1(h). It has the truncation
error of order O(h). By canceling the O(h) error, we define a new forward difference:
F2(h) = 2F1(h) - F1(2h)
The new approximation F2(h) is in fact the three-point forward difference:
The three-point forward difference is more accurate than the two-point difference: it
has the truncation error of order O(h2)!
3. Backward formula ' ( ) ( )( )
f x f x hf x
h
for first derivatives
4. Centered difference formula,
' ( ) ( )( )
2
f x h f x hf x
h
for first
derivatives Richardson extrapolation algorithm for central differences
Construct the following mapping from Fk(h) to Fk+1(h):
Fk+1 = Fk(h) + (Fk(h) - Fk(2h)) / (4k - 1) And we have
1 2
( ) 2 ( ) ( )f x h f x f x hF
h
, centered formula for second derivatives
54 | P a g e Richardson's Extrapolation
5. Generally
a. Centered difference formula is preferable to get more accurate approximation
derivative result
b. Making with same order having more equally spaced size h tends to accurate
approximation result (which means if h 0 , the error tends to zero, but
not equal to zero)
c. Use higher order error for getting good approximation of first and second
derivatives of a given function f(x).
d. MATLAB programming is useful for easily calculating the derivatives and
determining the order of the error
e. From the above plot we can see that for higher order the graph tends to zero
asymptotically.