0% found this document useful (0 votes)
8 views

Assignment1-Solutions

The document contains solutions to an assignment for a Numerical Methods and Modeling course at Lakehead University. It includes five questions covering topics such as numerical modeling, mathematical formulation, numerical error, Taylor series, and finite difference approximations. Each question provides a detailed analysis, computations, and MATLAB code where applicable.

Uploaded by

Zachariah Brown
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Assignment1-Solutions

The document contains solutions to an assignment for a Numerical Methods and Modeling course at Lakehead University. It includes five questions covering topics such as numerical modeling, mathematical formulation, numerical error, Taylor series, and finite difference approximations. Each question provides a detailed analysis, computations, and MATLAB code where applicable.

Uploaded by

Zachariah Brown
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Department of Software Engineering

Lakehead University

ESOF 3558: Numerical Methods and Modeling


Solutions to Assignment 1

Due Date: February 4, 2022

Solve the following problems. Each problem will require some analysis, as well as some
computations. Show your work for the computations. You may verify your solution using
MATLAB or your choice of other programming languages.

 Question 1 (Transforming an analytical model into a numerical model) (15 points)


Newton’s law of cooling says that the temperature of a body changes at a rate
proportional to the difference between its temperature and that of the surrounding
medium (the ambient temperature),

𝑘 𝑇 𝑇)

where T is the temperature of the body (C), t is the time (min), k is the proportionality
constant (per minute), and Ta is the ambient temperature (C). Suppose that a cup of
coffee originally has a temperature of 70C. Use Euler’s method to compute the
temperature from t = 0 to 20 min using a step size of 5 min if Ta = 20C and k =
0.019/min.

Solution:
Approximate the derivative by its finite difference equation:

Finite difference equation: |


Then place it in the differential equation and solve the equation for 𝑇 𝑡 .
T 𝑇
𝑘 𝑇 𝑇
∆t

Euler’s formula: T 𝑇 𝑘 𝑇 𝑇 ∆𝑡

Given values:
𝑡 0 min
𝑇 70℃
𝑇 20℃
∆𝑡 5min
k = 0.019/min

The first two steps can be computed as

T(5) = 70  0.019(70  20) 5 = 65.2500


T(10) = 65.2500  0.019(65.2500  20) 5 = 60.9513

The remaining results are displayed below.


t 0 5 10 15 20
T 70 65.2500 60.9513 57.0609 53.5401

 Question 2 (Modeling: mathematical formulation) (15 points)


Figure below shows a cylindrical tank with a conical base. If the liquid level is quite
low, in the conical part, the volume is simply the conical volume of liquid. If the liquid
level is midrange in the cylindrical part, the total volume of liquid includes the filled
conical part and the partially filled cylindrical part.

Develop a mathematical formulation that will determine the tank’s volume as a


function of given values of R and d. Write a MATLAB M-file to compute the tank’s
volume as a function of given values of R and d. Design the function so that it returns
the volume for all cases where the depth is less than 3R. Return an error message
“Overtop” if you overtop the tank – that is, d>3R. Test it with the following data:

R 0.8 1.8 1.6 1.6


d 0.9 1.35 4.7 4.9

Solution:

Let’s call v(R,d) as the volume of the liquid as a function of d and R.


1
𝜋𝑑 if 𝑑 𝑅
𝑣 𝑅, 𝑑 3
1
𝜋𝑅 𝜋𝑅 𝑑 𝑅 if 𝑅 𝑑 3𝑅
3

MATLAB M-file to solve the problem

function Vol= tankVolume(R, d)


if d < R
Vol= pi * d^3 / 3;
elseif d <= 3 * R
Vl = pi * R^3 / 3;
V2 = pi * R^2 * (d - R);
Vol= Vl + V2;
else
Vol= ' overtop';
end
end

Using the M-file, the values of the volume are as follows:

R 0.8 1.8 1.6 1.6


d 0.9 1.35 4.7 4.9
v(R,d) 0.7372 2.5765 29.2210 'overtop'

 Question 3 (Numerical error) (5 points)


A resistor labeled as 240 Ω is actually measured at 243.32753 Ω. What are the absolute
and fractional relative errors of the labeled value?

Solution:

Absolute error = 243.32753 – 240 ≈ 3.3 Ω.

Relative error |243.32753 – 240| / 243.32753 *100 ≈ 1.4%.

 Question 4 (Taylor series and truncation error) (10 points)


Use Taylor series expansion of f(x) = cos(x/2) to estimate the value of f(½) to an error
of at least 103.

Solution:

𝑥
𝑐𝑜𝑠 𝑥 1
2𝑛 !
∞ 𝜋𝑥
𝜋𝑥 2
𝑐𝑜𝑠 1
2 2𝑛 !
𝜋𝑥 𝜋𝑥 𝜋𝑥 𝜋𝑥
1 2 2 2 ⋯ 1 2 ⋯
2 ! 4 ! 6 ! 2𝑛 !

∞ 𝜋𝑥 𝜋𝜉
𝑅 1 2 1 2 , where 𝜉 is a number close to 𝑥.
2𝑖 ! 2 𝑛 1 !

Hence,
𝜋𝜉 1
|𝑅 |
2 2 𝑛 1 !

/
Note: the true value of 𝑐𝑜𝑠 𝑐𝑜𝑠 𝜋/4 1/√2 0.7071068

Error can be measured in terms of |Rn|, |t| or |a|.

When |Rn| is used as a measure of error, the parameter  can be set to the
operating point  = ½.

|t|: the true fractional relative error; i.e. the true error divided by the true value.
The true error is the difference of the true value and the approximated value.

|a|: the approximate percent relative error; i.e. the approximate error divided by
the new approximation. The approximate error is the difference of the new
approximation and the old approximation.

Results:

Iteration (n) Result* |a|% |t|% |Rn| ( = ½) %


0 1 41.42136 30.84251375
1 0.691575 44.59751 2.196545 1.585434424
2 0.707429 2.241121 0.045598 0.032599189
3 0.707103 0.046102 0.000504 0.000359086
4 0.707107 0.000508 3.46E‐06 2.46114E‐06

*Result of Iteration n is the sum of the n+1 terms of the Taylor series.
 Question 5 (Finite difference approximations of derivatives) (15 points)
Use forward, backward, and centered difference approximations to estimate the first
derivative of f(x) = (ex – 1)/x at x = 2 using the step size h = 0.5. Compare the true
percent relative error of each approximation.

Solution:

ex 1
f ( x)  Objective: find f’(2) using h = 0.5
x
We can find the true value of f’(2) by differentiating f analytically:

xe x  (e x  1) e x ( x  1)  1
f ( x) 
'
2
 2
 f ' (2)  2.097264
x x

Using forward difference method:


e 2.5  1 e 2  1

f (2  h)  f (2) f (2.5)  f (2) 2 . 5 2  2.556939
f (2) 
'
 
h 0.5 0.5
2.097264  2.556939
True error:  t   100  21.9178%
2.097264

Using backward difference method:


e 2  1 e1.5  1

f (2)  f (2  h) f (2)  f (1.5)
f ' ( 2)    2 1.5  1.746804
h 0.5 0.5
2.097264  1.746804
True error:  t   100  16.71034%
2.097264

Using centered difference method:


e 2.5  1 e 1.5  1

f (2  h)  f (2  h) f (2.5)  f (1.5) 2 . 5 1.5  2.151872
f ( 2) 
'
 
2h 1 1
2.097264  2.151872
True error:  t   100  2.60375% .
2.097264

The centred difference method yields the best approximation.

You might also like