You are on page 1of 26

College of Engineering

Department of Petroleum and Chemical Engineering


PNGE3202
Numerical Methods
Summer 2023

PROJECT
Submitted by

Student : Ahmed Mohammed Al-Harthi ID#133084

1
6th August 2023

Table of Content
Content Page Number
Objectives 3
Problem Statement 4
Introduction and Background 6
Methodology of Solution:
1) Regression Analysis 8
a) Linear Regression (LR) 8
b) Nonlinear Regression (NLR) 11
2) Interpolation 14
a) Newton’s Divided Difference Method (NDD) 14
b) Lagrangian Method (LM) 17
3) Error Analysis 19
b) Error Propagation 19
c) Condition Number (CN) 21
Results and Discussion 23
Conclusion 24
References 25

2
Objectives:

The purpose of this project is to apply three numerical methods, using two
different techniques for each method and then comparing the obtained values to
our case study problem mentioned in the problem statement section of this project.

These three methods used are :

 Fitting the given data of the experiment using Linear Regression and Non-
linear Regression.

 Interpolating to find the thermal expansion value of steel rail at a specific


temperature, using the experimental data, by Newton’s divided difference
method (NDD) and the Lagrangrain method (LD).

 Application of error analysis to our data using both condition number and
error propagation.

At the end of each Technique / Method, compare and discuss the approximated
values with the true values.

3
Problem Statement
The following experimental data was obtained after an experiment to find thermal
expansion at different temperatures.
T (℃) ∆ L(mm)
-15 21.113
-5 21.187
0 21.755
5 24.230
10 25.988
15 26.435
20 28.221
Table 1: Measured thermal expansion at different temperatures.

 The thermal expansion of a Lo=20 m=20× 103 mm long steel rail is measured
to observe it for this experiment.
 Temperature Range :{ -15℃ to 20℃ }

The data above in Table 1 shows the change in length {∆ L ( mm ) } with a subjective
zero point at different seven temperatures in {℃ } starting at -15 to 20 and an
initial length of 20 ×103 mm of a steel rail.
The model describes how the steel rail undergoes thermal expansion:
∆ L=α Lo T + ∆ Lo (1)
Where,
 ∆ L: Change in length of the steel rail due to the change in temperature.
 α : Thermal expansion coefficient of the steel rail.
 Lo : Length of the steel rail (at reference point) .

4
 T : Change of temperature comparing to the reference point.
 ∆ Lo : Constant value that represents some offset in length that might be
present even when the temperature change is zero.

Using three numerical techniques and investigations, and determining the


following using the data from Table 1:

A. Use least square regression to fit the data into a straight line. Similarly, the
second order polynomial utilizing multi-least square regression.
Determine the steel expansion coefficient (α ¿ where the true value is
11.49 x 10-6 mm/mm.℃

B. Use cubic interpolating techniques ( NDD and LD) to estimate ∆ L value at


a temperature of 8℃ , noting that the True value is 24.0384 mm.

C. Use error propagation at T = 5℃ and assuming the temperature


measurements has no uncertainty to find the error analysis, where the
uncertainty length change value is 2.0000 mm. Additionally, apply the
same to obtain condition number (CN) at these temperatures ( -15℃ , 0
℃ , 15 ℃).

5
Introduction and background

Thermal expansion is a natural phenomenon that


takes place when a material expands as a reaction
when it undergoes an increase in temperature. Just
like how our bodies feel warmer when we're
active, the particles within the material gain more
energy and move all around more as the
temperature increases causing significant
expansion of the material.
Figure 1: Illustration of thermal expansion as
temperature increases.

Thermal expansion is an event that happens


to all types of materials, and it has practical
implications for engineers and designers.
They need to consider how materials will
react to changes in temperature when
creating different products, whether it's
bridges, buildings, or everyday consumer
goods. Figure 2: Effect of thermal expansion in piping systems

Thermal expansion is essential for petroleum engineers in designing and operating


oil and gas substructure effectively, accounting for dimensional changes in
equipment and structures caused by varying temperatures during production
processes, ensuring safety and reliability in the petroleum industry.

“ Thermal expansion is among the more serious of plumbing concerns, but one
that many homeowners know little about. Because many homes aren't at risk, it
rarely seems to enter the typical plumbing discussion. Of the homes that are, many

6
lack adequate protection since code requirements are often only enforced on new
installations.”1

When a material undergoes thermal expansion its shape, volume, and area can
change. Temperature is a way to measure the average energy of the material's
particles. So, when the material is heated, the particles gain more energy, and they
start to vibrate which can increase the space between the particles. This
temperature driven expansion is typically not very noticeable or significant and it
occurs within a specific temperature range called strain. Scientists and engineers
use the coefficient of thermal expansion to quantify this effect and it usually varies
with temperature.

Consider an object with an initial length denoted as Lo at a certain temperature.


When the temperature changes by ∆T, the length of the object changes by an
amount ∆L. To appropriately analyze the fractional change in length per degree of
temperature change, we define the average coefficient of linear expansion as α,
which can be expressed in 2 ways :
1 dL ∆ L/ Li
α=
Li dT
(2) , α≡
∆T
(3)
Experimental evidence shows that α remains constant for small temperature
variations. For practical calculations, we often rewrite the equation as:
∆ L=α Li ∆ T (4)

Or could rarely written as:


Lf −Li=α Li ( T f −T i ) (5)

Where,
 Lf : Final length
 Li : Initial length
 T f : Final Temperature

1
https://www.plumbingsupply.com/thermal-expansion.html

7
 T i : Initial Temperature
 α : The mean coefficient of linear expansion for a specified material and has
units of (℃)−1 /1 ≈(mm /mm ∙℃)or (℉ )−1/ 1 ≈ (mm/mm ∙ ℉) .

Methodology of Solution

First Technique : Least Square Regression


The least squares technique is a way to find the closest match for a set of data
points by reducing the differences between the points and a line on a graph. By
using this method, it is possible to create a line that shows the connection between
almost every two types of variables.

Method (A) : Linear Regression (LR)


This method commonly known as "linear" or "ordinary" aims to create a straight
line that best fits the data by minimizing the errors between observed and
predicted values. These errors are represented by squared residuals, measuring the
differences between actual and expected outcomes based on the model. The
expression is :
∆ L=α Lo T + ∆ Lo (6) ∆ L=b1 T +b 0 (7)

Where b 0and b 1 are coefficients representing the slope and the intercept of the
mathematical equations above { (6), (7) }.
The table below shows necessary calculations to regress the experimental data:

i xi (T) yi ∆ L
( ) x2 x⋅y (yi-y)2 (yi-b0-b1xi)2
1 -15 21.113 225 -316.69 8.33476 2.3211
2 -5 21.187 25 -105.93 7.91296 0.47621
3 0 21.755 0 0 5.04002 1.60247
4 5 24.230 25 121.15 0.05290 4.264 x10-3
5 10 25.988 100 259.88 3.95214 0.46170
6 15 26.435 225 396.52 5.92922 2.998x10-3

8
7 20 28.221 400 564.42 17.8168 0.39046
- - - - - - -
n= ∑T. ∆ L
∑T=30 ∑∆ L =168 ∑T2=1000 ∑=49.0388 ∑=5.259202
7 =919.35
Table 1: Linear Regression Calculation
n=7

∑T 30
T = i=1 = =4.28
n 7
7

∑∆L 168
∆ L= i=1 = =24
n 7

n ST ∆ L−S ∆ L ST
b 1=
2 ( 7 ) ( 919.35 )−(168)(3 0)
n ST −(S ¿¿ T ) =
2 =0 .228762¿
( 7 ) ( 1000 )−(3 0)2

b 0=∆ L−a1 T=24− ( 0 .228762 )( 4.28 )=23.02089

b 1=α Lo

b1 0.228762 −5
α= = 3
=1 .14381× 10
Lo 20 ×10

Hence, the least square fit can be expressed in this linear equation:
∆ L=b0 +b 1 T =0 .228762 T +23.02089

The sum of the squares of deviation from the mean:


7
St =∑ ( y i− y )2=∑ ( ∆ Lmeasured −∆ L ) =¿ 49.0388
2

i=1

The sum of the square of residuals :


7
Sr =∑ ( y i−b0 −b1 xi )2=∑ ( ∆ Li−a 0−a1 T i ) =¿5.259202
2

i=1

The Standard deviation:

9
S y=
√ St
n−1
=2.858869

The standard error of estimate:

S y / x=
√ Sr
n−2
=1.02559

Thus, because S y / x < S y , the linear regression model has permit. The extent of the
improvement is quantified by the coefficient of determination:
2 St −Sr
r= =0.89275
St

These results indicate that 89.275 % of the original uncertainty has been explained
by the linear model.

Finding the absolute true error:

| |
α true value −α
| |
−6 −6
11.49× 10 −1 0.833 ×10
|ϵt|%= α true value
×100 %= −6
× 100 % = 5.7180%
11.5× 10

Plotting using MATLAB:

10
Figure 3: Linear regression plot (∆L versus T) model using MATLAB.

Code:

11
Method (B) : Quadratic Regression (LR)
A nonlinear model includes models where the functional relationship between
variables is not a straight line regarding the unknown parameters. Multiple least
squares regression is a prevalent form of multiple regression that employs the least
squares method to adjust the model to the data by estimating the unknown
parameter values. Explicitly, the second-order polynomial is an example of such a
mathematical expression expressed as :
2
∆ L=b0 +b 1 T +b2 T (6)

¿ b 0 z 0 +b1 z 1+ b2 z 2 (7)

2
Where, the mentioned functions above are monomials { z 0=1/ z 1=T / z 2=T }

Equation (7) can be rewritten in a matrix form as :

12
{ ∆ L }=[ Z ] { A }+ {E }
−1
{ A }= [ [ Z ] [ Z ] ]
T
[ [ Z ] T {∆ L}]
Setting the data inside the matrices :

[ ] []
1 −15 225 21.113
1 −10 100 21.187
1 −5 25 21.755
[Z ]= 1 0 0 {∆ L}= 24.230
1 5 25 25.988
1 10 100 26.435
1 15 225 28.221

Now doing the other mathematical matrix operations :

[ ]
1 1 11 1 1 1
T
[Z ] = −15 −10 5 0 5 10 15
225 100 25 0 25 100 225

[ ] [ ]
7 0 700 168.949
[ [ Z ]T [ Z ] ]= 0 700 0 [ [ Z ]T {∆ L }]= 179.965
700 0 122500 17060.425

[ ]
−1
0.33333 0 −1.9047 × 10−3
[ [ Z ]T [ Z ] ] = 0 1.4285 × 10
−3
0
−3
−1.9047 × 10 0 1.9047 × 10−5

[ ]
−1 23.821336
{ A }= [ [ Z ] [ Z ] ]
T
[ [ Z ] T {∆ L}]= 0.2570800
0.00315275

b 0=19.84321

b 1=0.2570800

b 2=0.00315275

13
Substituting in equation(6) :

2
∆ L=19.84321+ 0.2570800 T +0.00315275 T

Doing the same procedure as Method(A):


n=7

m+1=3

∑T
T = i=1
n
7

∑∆L
∆ L= i=1
n
7
Sr =∑ ( ∆ Li −a0 −a1 T i )
2

i=1

7
St =∑ ( ∆ L−∆ L )
2

i=1

S y / x=
√ Sr
n−(m+1)

S y=
√ St
n−1

The sum of the square errors = 1.2 ×10−5

2
r =0.942

14
Second Technique : Interpolation

Method (A) : Newton’s Divided Difference Method (NDD)


∆ L=z 0+ z 1 (T −T 0 )+ z 2 (T −T 0 )(T −T 1 )+ z3 (T −T 0 )(T −T 1 )(T −T 2) (8)

Where,

z 0=f [ x 0 ]

z 1=f [ x 1 , x 0 ]

z 2=f [ x 2 , x 1 , x 0 ]

z 3=f [ x 3 , x2 , x1 , x 0 ]

∆ L=z 0+ z 1 (T −T 0 )+ z 2 (T −T 0 )(T −T 1 )+ z3 (T −T 0 )(T −T 1 )(T −T 2) (9)


Where,

z 0=f [ x 0 ]

z 1=f [ x 1 , x 0 ]

z 2=f [ x 2 , x 1 , x 0 ]

z 3=f [ x 3 , x2 , x1 , x 0 ]

Figure 4: Divided difference for cubic polynomial.

The closest four data point to T=8:

T 0=15 , ∆ L ¿T=15=26.435

T 1=10 , ∆ L¿ T=10=25.988

T 2=5 , ∆ L¿ T=5=24.230

T 3=0 , ∆ L ¿T =0 =21.755

15
Calculating z 0 , z 1 , z 2 ,∧z 3 values:

T 0=15 26.435 0.0894 0.05244


T 1=10 25.988 0.3516 4.452 x10-3
T 2=5 24.230 0.495 -0.01434
T 3=0 21.755

That is:

z 0=26.435

z 1=0.0894

z 2=0.05244

−3
z 3=4.452× 10

Substituting in equation (8)


−3
∆ L=26.435+0.0894 ( T −15 )+ 0.05244 ( T −15 ) ( T −10 ) +4.452 ×10 ( T −20 ) (T −10)( T −5)

Which can be evaluated at T =8 ° C :


−3
∆ L(8)=21.967−0.16220 ( 8−20 )+ 0.04275 ( 8−20 )( 8−10 ) +2.48565 ×10 ( 8−20 ) (8−10)(8−30)

∆ L(8)=23.626 mm

Truncation Error:

R3=z 4 ( T −T 0 ) ( T −T 1 )( T −T 2 ) ( T −T 3 ) (9)

16
Finding the value of z 4:

T 0=15 26.435

0.08940

T 1=10 25.988 −0.02622


-4
0.35160 -7.92× 10

T 2=5 24.230 -0.01434 -5


3.973× 10
-3
0.49500 -1.58667× 10

T 3=0 21.755 0.03814

0.11360

T 4=−5 21.187

Substituting z 4 =3.973×10 -5, T 0=15, T 1=10, and T 2=5 in (9)


-5
R3=3.973×10 ( T −15 ) ( T −10 ) ( T −5 ) ( T −0 )

Which can be valued at T =8 ° C :


-5
R3=3.973×10 ( 8−15 ) ( 8−10 )( 8−5 ) ( 8−0 )
R3=0.013349

Finding the absolute true error:

17
|ϵt|%= | ∆ Ltrue value−∆ Linterpolated
∆ Ltrue value |
×100 %

¿|24.0384−23.626
24.0384 |×100 % = 1.70086%

Method (B) : Lagrangian Method


n
f n ( x )=∑ p n ,i ( x ) f (x i)
i =0

n
x−x
Where, pn , i ( x ) : ∏
j

j=0 xi −x j
j ≠i

Considering : ∆ L=x
3
x (T )=∑ p i ( T ) x ( T i)
i=0

x (T )= p 0 ( T ) x ( T 0 ) + p1 ( T ) x ( T 1 )+ p 2 ( T ) x ( T 2 )+ p 3 ( T ) x (T 3 )

T 0=15 , x ( T 0 )=26.435

T 1=10 , x ( T 1 )=25.988

T 2=5 , x ( T 2 )=24.230

T 3=0 , x ( T 3 )=21.755

Finding the Lagrangian basis polynomials p0, p1, p2, and p3:

18
( )( )( )
3
T −T j T −T 1 T −T 2 T −T 3
p0 ( T ) = ∏ =¿ ¿
j=0 T 0−T j T 0−T 1 T 0 −T 2 T 0−T 3
j ≠0

( )( )( )
3
T −T j T −T 0 T −T 2 T −T 3
p1 ( T ) = ∏ =
j =0 T 1−T j T 1−T 0 T 1−T 2 T 1−T 3
j ≠1

( )( )( )
3
T −T j T −T 0 T −T 1 T −T 3
p2 ( T ) = ∏ =
j =0 T 2−T j T 2 −T 0 T 2−T 1 T 2−T 3
j ≠2

( )( )( )
3
T −T j T −T 0 T −T 1 T −T 2
p3 ( T ) = ∏ =
j=0 T 3 −T j T 3−T 0 T 3−T 1 T 3−T 2
j ≠3

x (T )=
( T −T 1
T 0 −T 1 )( T −T 2
T 0−T 2 )( T −T 3
T 0 −T 3 )
x (T0)+
T −T 0
T 1−T 0 ( )( T −T 2
T 1−T 2 )( T −T 3
T 1−T 3) (
x (T 1)+
T−T 0
T 2−T 0 )( T −T 1
T 2−T 1 )( T −T 3
T 2−T 3)x (T

Evaluating at T =8 ° C :

x ( 8 )= ( 15−10
8−10
)( 15−5
8−5
)( 15−0
8−0
) 26.435+( 10−15
8−15
)( 10−5
8−5
)( 10−0
8−0
) 25.988+( 8−15
5−15 5−10 )( 5−0 )
)( 8−10 8−0
24.230+

x ( 8 )=(−0.064 ) 26.435+ ( 0.672 ) 25.988+ (−0.06400 ) 24.230 5+ ( 0.448 ) 21.755=23.9675

Hence, the thermal expansion (∆ L)=23.9675 mm at T =8 ° C .

Finding the absolute true error:

|ϵt|%= | ∆ Ltrue value−∆ Linterpolated


∆ Ltrue value |
×100 %

¿|24.0384−23.9675
24.0384 |× 100 %
¿ 0.2949 %

19
Third Technique : Error Analysis

Method (A) : Error Propagation

∆ f (~x )=|f ' ( ~x)|∆ ~


x

(13)

Where,

∆f left (widetilde {x} right ) = left lline f left (x right ) -f left (widetilde {x} right ) right rline
: Shows an estimate of error of the function.

∆ widetilde {x} = left lline x- widetilde {x} right rlin ” : Shows an estimate of the
error of x .

From the equation above:

∆ L−∆ Lo
α=
T Lo

Substitute x=∆ L , we get:

x−∆ Lo
α =f (x)=
T Lo

24.230

Given data:

T =5 ℃

∆ Lo =20 mm

20
~
x=24.230 ± 2.000 mm

Obtaining First derivative:

' 1
f ( x )=
T Lo

1
f (~
' ' −5 −1
x )=f ( 24.230 )= =1× 10 (mm . ℃)
(5 ℃)(20,000 mm)

Substituting the values to find ∆ f (~x ):

∆ f (~x )=|1 ×10−5 ( mm . ℃ )−1|( 2.000 mm ) =2× 10−5 mm/mm ∙ ℃

Substituting in f ( x )to find f ( ~x ) value:

24.230 mm−20 mm
f (~
−5
x )=f ( 24.230 )= =4.23 × 10 mm/mm ∙ ℃
(5 ℃)(20,000 mm)

Hence,

α =( 4.23 ×10−5 ± 2× 10−5 ) mm /mm ∙ ℃

Based on error propagation method, α value range is :

[ 4.23 × 10−5 +2 ×10−5 ∧4.23 ×10−5−2 ×10−5 ]

[ 6.23 ×10−5∧2.23 ×10−5 ]

The true value for the above range is :

21
−5
α true value=1.46 ×10 mm/mm . ° C

Method (B) : Condition Number (CN)

The condition number is expressed as:


'
x f (x)
CN =
f (x)

After substitutions in above equations:

∆ L−∆ Lo
α=
T Lo

Substitute x=∆ L gives:

x−∆ Lo
α =f (x)=
T Lo

Obtaining the first derivative:

' 1
f ( x)=
T Lo

Given data:

Lo=20,000 mm, ∆ Lo =2.000 mm.

22
Substituting:

CN =
'
x f (x)
( x)
=
( T1L ) =
o x
=
x

( )
f (x) x−∆ Lo x−∆ Lo x−2.000
T Lo

At first Point:

T =−15 ℃ , x (∆ L)=¿ 21.113mm

21.113
CN = =1.10464
21.113−2.000

At second Point:

T =0 ℃ , x (∆ L)=¿ 21.755 mm

21.755
CN = =1.10124
21.755−2.000

At Last Point:

T =15 ℃ , x (∆ L)=¿ 26.435mm

26.435
CN = =1.08184
26.435−2.000

Results and Discussion


Thermal Expansion Regression Analysis:
The thermal expansion regression model was determined through two approaches.
The first model, obtained from linear regression, is given by ∆L =
0 .228762 T +23.02089 , with a coefficient of determination r2 of 0.89275 . The second
model, derived from quadratic regression, is represented as ∆L =
2
19.84321+0.2570800 T + 0.00315275 T , with an r value of 0.942. The coefficient of
2

determination indicates the data coverage capability of each curve, with the

23
quadratic regression (94.20%) outperforming the linear regression (89.275%).
Therefore, quadratic regression is preferred for fitting the data.
Determination of ∆L at T=8℃:
Through the Lagrangian and NDD methods, the value of ∆L at T=8℃ was found
to be 23.626 mm, both with a true error of 1.70086%. The accuracy of these
methods is evident as their true errors fall below 5%, which is considered excellent
for approximation mathematical approaches.
Error Analysis of Thermal Expansion Coefficient (α):
Applying the error propagation method at ∆L=2.000 mm, the error at T=5 ℃ and
L=24.230 mm was calculated to be 2×10-5 mm/mm.℃. This error is relatively
small compared to the uncertainty in L. Additionally, the condition number at
T= -15 ℃ was found to be higher than at T=15 ℃, indicating lower stability of
the thermal expansion coefficient at T= -15 ℃. However, both cases are
considered stable and well-conditioned since the condition number values are
close to 1.

Conclusion
In this project, the focus was on studying thermal expansion using different
numerical methods. The main equation we used represents how a material expands
in one dimension as the temperature changes. We wanted to see which numrical
method works best in terms of accuracy and precision.
Firstly, Least-Squares Regression method was applied to fit the data to a straight
line and a second-order polynomial. After analyzing the results it was found that

24
the higher order regression (with a higher determinant coefficient value, r2)
provided a better fit.
Next, we explored cubic interpolating techniques specifically Lagrangian and
NDD. These methods helped us determine the thermal expansion (∆L) at a specific
temperature (T=8℃ ) with smallest error and high accuracy.
To detailed analyzes for the thermal expansion coefficient model, I used two error
analysis numerical methods (Error Propagation and Condition Number). These
methods allowed us to gain deeper understandings into the data.
In conclusion, this project showed that utilizing many numerical techniques in data
analysis can lead to interesting and valuable results. It highlighted the importance
of using multiple approaches to gain a complete understanding of given data.

References
 The "MATLAB Code for Newton's Divided Difference Formula" can be
accessed through the following link: https://www.youtube.com/watch?
v=_pbfOxAlH9I.
 MATLAB (Online version) accessed through the following link:
https://matlab.mathworks.com/
 [1] https://www.plumbingsupply.com/thermal-expansion.html

25
 Bergmann, T. L., Laverne, A. S., Incr0pera, F. P., & Dew1tt, D. P.
(2002). Fundementals of heat with mass transfer (sixth Edition). WILEY
 Matrices operations were operated using:
https://www.emathhelp.net/en/calculators/linear-algebra/matrix-calculator/?
op=*&p=&c=&a=%5B%5B1%2C1%2C1%2C1%2C1%2C1%2C1%5D
%2C%5B-15%2C-10%2C-5%2C0%2C5%2C10%2C15%5D%2C
%5B225%2C100%2C25%2C0%2C25%2C100%2C225%5D%5D&b=%5B
%5B1%2C-15%2C225%5D%2C%5B1%2C-10%2C100%5D%2C
%5B1%2C-5%2C25%5D%2C%5B1%2C0%2C0%5D%2C
%5B1%2C5%2C25%5D%2C%5B1%2C10%2C100%5D%2C
%5B1%2C15%2C225%5D%5D
 https://amarineblog.com/2020/04/09/thermal-expansion-affections-in-
piping-system/

26

You might also like