You are on page 1of 17

FACULTY OF CIVIL ENGINEERING AND BUILT ENVIRONMENT

CIVIL ENGINEERING MATHEMATIC IV

BFC24203

SEM 1 SESSION 2020/2021

GROUP ASSIGNMENT

NUMERICAL DIFFERENTIATION

SUBJECT CODE BFC24203

SECTION 2

GROUP L
1. MUHAMMAD ILHAM BIN MAT YAJID (DF180110)
MEMBERS 2. NUR AINA ATIRAH BINTI OTHMAN (CF190100)
3. MUHAMMAD SALAHUDDIN BIN MAT NOR (CF180162)
LECTURER DR.HENDRY FITRIAN SUHANDRI
TABLE OF CONTENTS

NO CONTENT PAGE
NUMBER
1.0 INTRODUCTION 2-4

2.0 OBJECTIVE 5

3.0 PROBLEM STATEMENT 5

4.0 METHODOLOGY 6-9

5.0 RESULT AND DATA ANALYSIS 10-14

6.0 CONCLUSION 15

1
1.0 INTRODUCTION

Civil Engineering Mathematic IV is a compulsory subject for all Civil Engineering student in
University Tun Hussein Onn Malaysia (UTHM). Before taking Civil Engineering Mathematic IV
subject, students need to pass Civil Engineering Mathematic I, II and III.

For this assignment, we are asked to use numerical differentiation to solve the problems
of function where the function is not easily differentiated analytically or only a set of data is
given The problem of numerical differentiation does not receive very much attention nowadays.
Although the Taylor series plays a key role in much of classical analysis, the poor reputation
enjoyed by numerical differentiation has led numerical analysts to construct techniques for most
problems which avoid the explicit use of numerical differentiation. One may briefly and roughly
define the term numerical differentiation as any process in which numerical values of derivatives
are obtained from evaluations of the function at several abscissae near. Taylor series allows us to
expand a function into an infinite series. If the function is infinitely differentiable at number h,
we can use the Taylor series to approximate the function. We can derive the backward, the
forward, and the center divided difference methods using Taylor series, which also give the
quantitative estimate of the error in the approximation.

MATLAB is a programming platform designed specifically for engineers and scientists.


The heart of MATLAB is the MATLAB language, a matrix-based language allowing the most
natural expression of computational mathematics. As the MATLAB is a matrix-based, we were
given an assignment by using this software. This assignment required us to solve the equation of
numerical differentiation.

Differentiation is defined as rate of change. Many physical situations involve rate of


change. For example, velocity is the rate of change of distance with respect to time while
acceleration is the rate of change of velocity with respect to time. The rate of change of a graph y
= f(x) against x, is the gradient of the curve y. this is equivalent to finding the slope of the
tangent line to the function y = f(x) at a point. In cases where a function is not easily
differentiated analytically or only a set of data given, numerical differentiation can be used.
Numerical differentiation is one of the chapter in Civil Engineering Mathematic IV subject. In

2
this chapter , we will know how to approximate the first derivative by using 2-point forward, 2-
point backward, 3-point central and 5-point formulas whereas second derivative can be
approximated from 3-point central and 5-point formulas for a tabulated data with the increment
of h.

Difference formula for a function of a single variable can be developed using Taylor’s
series. The Taylor’s series expansion for f(x+h) can be written as below;

f ( x +h ) =f ( x ) +h f ' ( x ) + f (x)} over {2!} {h} ^ {2} + {{f} ^ {'''} left (x right )} over {3!} {h} ^ {3} +…+ {{f} ^ {(

Considering only the first derivative (do not have higher derivatives or very small), we can use
this formula;

f ( x+ h )−f (x )
For first derivative 2-point forward, f ' ( x )=
h

f ( x )−f ( x−h )
For first derivative 2-point backward, f ' ( x )=
h

f ( x+ h )−f ( x−h)
For first derivative 3-point central, f ' ( x )=
2h

The first derivative for 2-point forward, 2-point backward and 3-point central can be shown
graphically.

a) 2-point forward

Figure 1

3
b) 2-point backward

Figure 2

c) 3-point central

Figure 3

4
2.0 OBJECTIVE

Objectives for this assignment are:

 To obtain the output of numerical differentiation for 2-point forward, 2-point


backward and 3-point central using MATLAB application.
 To analyze and compare the differences of output between three formula used
 To expose students about the relationship of numerical method in programming
and real condition in engineering field.

3.0 PROBLEM STATEMENT

In this project assignment, we were asked to solve the Numerical differentiation equation by
using Matlab application in learning slide page 12 which consist of two question which is;

1) Given f(x) = ex. By taking h= 10-k , where k=1,2. Find f’(2.2) using;

a) 2-point forward difference formula

b) 2-point backward difference formula

c) 3-point central difference formula

*All in 6 decimal places

2) Let f(x) = ln(x) and x = 3. Using 2-point forward and 3-point central difference and working to
8 decimal places, approximate f’(x) using h = 0.1 and h = 0.01.

5
4.0 METHODOLOGY

Numerical differentiation that we learn in Chapter 5 Civil Engineering Mathematic IV consists


of two parts. The first part is about First Derivative and next part is Second Derivative. However,
in this assignment we were asked to solve numerical differentiation problem using First
Derivative of Taylor’s series.

4.1 Step

Step 1: Solve the problem by using formula First Derivative of Taylor’s series.

 2-point forward
i. From the problem statement, identify the function of y(x)
ii. Identify the value of point concern, x
iii. Identify the distance between the point, h
iv. Using the point data after the point concern, the derivative can be expressed as the
slope or gradient.

y ( x +h ) − y ( x)
y’(x) =
h

 2-point backward
i. From the problem statement, identify the function of y(x).
ii. Identify the value of point concern, x
iii. Identify the distance between the point, h
iv. Using the point data before the point concern, the derivative can be expressed as
the slope or gradient.

6
y ( x )− y ( x+ h )
y’(x) =
h

 3-point central
i. From the problem statement, identify the function of y(x).
ii. Identify the value of point concern, x
iii. Identify the distance between the point, h
iv. Using the point data before and after the point concern, the derivative can be
expressed as the slope or gradient.

y ( x +h ) − y ( x−h )
y’(x) =
2h

Step 2: Write coding in MATLAB

Set input for function


Set iput for h value
set input for derivative function
1 Set input for x value

Define derivative function as 1


Use the if-else condition
2 Write the formula for 2-point forward, 2-pointbackward, 3-point central

Run the coding


Enter to display the results
3

7
8
4.2 Command

Question 1

f = input('Enter your function e.g @(x) exp(x) : ');


h1 = input('Enter step size h1: ');
h2 = input ('Enter step size h2:');
d = input('Which derivative you want to compute: ');
x = input('At which point you want to approximate derivative: ');
if d == 1
Fd2(1) = (f(x+h1)-f(x))/h1; %forward 2-point
Fd2(2) = (f(x+h2)-f(x))/h2; %forward 2-point
Bd2 (1)= (f(x)-f(x-h1))/h1; %backward 2-point
Bd2 (2)= (f(x)-f(x-h2))/h2; %backward 2-point
Cd3 (1) = (f(x+h1)-f(x-h1))/(2*h1); %central 3-point
Cd3 (2) = (f(x+h2)-f(x-h2))/(2*h2); %central 3-point
disp('Results using 2-point forward formulas');
fprintf('Forward h1: %.6f\n',Fd2 (1));
fprintf('Forward h2: %.6f\n',Fd2 (2));

disp('Results using 2-point backward formulas');


fprintf('Forward h1: %.6f\n',Bd2 (1));
fprintf('Forward h2: %.6f\n',Bd2 (2));

disp('Results using 3-central difference');


fprintf('CentraL h1: %.6f\n',Cd3 (1));
fprintf('CentraL h2: %.6f\n',Cd3 (2));

else
disp('**Formula not available**')

end

Published with MATLAB® R2020b

9
Question 2

f = input('Enter your function e.g @(x) log(x) : ');


h1 = input('Enter step size h1: ');
h2 = input ('Enter step size h2:');
d = input('Which derivative you want to compute: ');
x = input('At which point you want to approximate derivative: ');
if d == 1
Fd2(1) = (f(x+h1)-f(x))/h1; %forward 2-point
Fd2(2) = (f(x+h2)-f(x))/h2; %forward 2-point
Cd3 (1) = (f(x+h1)-f(x-h1))/(2*h1); %central 3-point
Cd3 (2) = (f(x+h2)-f(x-h2))/(2*h2); %central 3-point
disp('Results using 2-point formulas');
fprintf('Forward h1: %.8f\n',Fd2 (1));
fprintf('Forward h2: %.8f\n',Fd2 (2));
disp('Results using 3-central difference');
fprintf('CentraL h1: %.8f\n',Cd3 (1));
fprintf('CentraL h2: %.8f\n',Cd3 (2));

else
disp('**Formula not available**')

end

Published with MATLAB® R2020b

10
5.0 RESULT AND DATA ANALYSIS

5.1 Results

Manual Calculation:

Question 1

Given f(x) =e x , by taking h =10−k where k = 1, 2. Find f’(2.2) using

2 point forward difference method

x = 2.2, h =0.1

f ( x+ h )−f ( x )
f’(x) =
h

e2.2 +0.1−e2.2
=
0.1

= 9.491690

x = 2.2, h = 0.01

f ( x+ h )−f ( x )
f’(x) =
h

e2.2 +0.01−e 2.2


=
0.01

= 9.070289

2 point backward difference method

x= 2.2, h =0.1

f ( x )−f ( x−h )
f’(x) =
h

e2.2 −e 2.2−0.1
=
0.1

11
= 8.588436

x =2.2, h=0.01

f ( x )−f ( x−h )
f’(x) =
h

e2.2 −e 2.2−0.01
=
0.01

= 8.980038

3 point central difference method

x = 2.2, h = 0.1

f ( x+ h )−f ( x−h )
f’(x) =
2h

e2.2+0.1−e2.2−0.1
=
2(0.1)

= 9.040063

x = 2.2, h =0.01

f ( x+ h )−f ( x−h )
f’(x) =
2h

e2.2+0.01−e 2.2−0.01
=
2(0.1)

= 9.025164

12
Question 2:

Let f(x) = ln(x) and x = 3. Using 2-point forward and 3-point central difference and working to 8
decimal places, approximate f’(x) using h = 0.1 and h = 0.01.

2 point forward method

x = 3, h =0.1

f ( x+ h )−f ( x )
f’(x) =
h

ln ( 3+0.1 )−ln ⁡(3)


=
0.1

= 0.32789823

x = 3, h =0.01

f ( x+ h )−f ( x )
f’(x) =
h

ln ( 3+0.01 )−ln ⁡(3)


=
0.01

= 0.33277901

3 point central method

x = 3, h =0.1

f ( x+ h )−f (x−h)
f’(x) =
2h

ln ( 3+0.1 )−ln ⁡(3−0.1)


=
2(0.1)

= 0.33345687

x = 3, h =0.01

13
f ( x+ h )−f (x−h)
f’(x) =
2h

ln ( 3+0.01 )−ln ⁡(3−0.01)


=
2(0.01)

= 0.33333457

Results using MATLAB;

Question1

MATLAB Command Window Page 1


>> numerical_diff_1
Enter your function e.g @(x) exp(x) : @(x) exp(x)
Enter step size h1: 0.1
Enter step size h2:0.01
Which derivative you want to compute: 1
At which point you want to approximate derivative: 2.2
Results using 2-point forward formulas
Forward h1: 9.491690
Forward h2: 9.070289
Results using 2-point backward formulas
Forward h1: 8.588436
Forward h2: 8.980038
Results using 3-central difference
CentraL h1: 9.040063
CentraL h2: 9.025164

Question 2

MATLAB Command Window Page 1


>> numerical_diff_2
Enter your function e.g @(x) log(x) : @(x) log(x)
Enter step size h1: 0.1
Enter step size h2:0.01
Which derivative you want to compute: 1
At which point you want to approximate derivative: 3
Results using 2-point formulas
Forward h1: 0.32789823
Forward h2: 0.33277901
Results using 3-central difference

14
CentraL h1: 0.33345687
CentraL h2: 0.33333457

5.2 Data Analysis

Based on the results for Question 1, the results we obtained by using the first derivative 2-point
forward formulas for h=0.1 is 9.491690 while for h=0.01 is 9.070289. As we can see, the result
shows that there are the differences. This is because, the smaller value of h, the accurate results
obtained. However, this relationship cannot be applied to the first derivative 2-point backward
formulas. The results when h=0.1 is 8.588436 and for h=0.01 is 8.980038. From the results, we
can conclude that the smaller number of h, the higher value of function (f(x)). For the last, the
first derivatives of 3-point central difference were calculated. It is because this formula was a
better approximation since more points are considered. By applying this formula, the value for
h=0.1 and h=0.01 were obtained. Result shows that the output for h=0.1 is 9.040063 while for
h=0.01 is 9.025164. As we can see, by using the 3-point central differences formulas, the results
of f(x) were just slightly different. This also can conclude that the smaller value of h, the better
approximation that we obtain.

For question 2, the formula used is 2-point forward and 3-point central difference. By
using 2-point forward formula, the results shows that h=0.1 has high small value than h=0.01
which is 0.3278923 and 0.33277901 respectively. The differences between the result is because
the value of h. the smaller value of h, the higher value of f(x). Then, the results for 3-point central
differences were slightly different. Value f(x) for h=0.1 is 0.33345687 and h=0.01 is 0.33333457.
by referring to the results of 3-point central difference, we can conclude that the smaller value of
h, the precise approximation of the f(x).

15
6.0 CONCLUSION

The objectives for this assignment were achieved as the we obtained the output for 2-
poiint forward, 2-point backward and 3-point central. For question 1, the results of 2-point
forward for h1 and h2 were 9.491690 and 9.070289 respectively. Then the result for h1 and h2 in
2-point backward is 8.588436 and 8.980038 each. Lastly, the result show for 3-point central is
9.040063for h1 and 9.025164 for h2. For question 2, the output using 2-point forward for h1 is
0.32789823 and h2 is 0.33277901. Meanwhile, the 3-point central gave output for h1 and h2 as
0.33345687 and 0.33333457 respectively.

After the output was obtained, we then analyse the results and compare the differences.
As we can see, the output does show the differences when using different formulas. Hence, this
shows that our second objective was achieved. Next, the third objective is to expose students
about the relationship of numerical method in programming and real condition in engineering
field. By doing this assignment, we gain more knowledge especially about MATLAB. Other than
mastering in calculation, we also can improve our skills in programming that we believe will
help us a lot in future when in engineering field.

It can be concluded that this assignment gave us more knowledge either in calculation or
programming. We hope this assignment can be continued for this subject to help improving the
understanding of student about numerical differentiation and it relationship with MATLAB.

16

You might also like