Numerical Engineering
Numerical Engineering
In this segment we're going to talk about round-off errors. There are several possibilities of error
whenever you're going to use numerical methods, but we want to concentrate here on just two
errors, one is the round-off error and the other is the truncation error.
So those are the sources of error which we are going to talk about, because those are the ones which
are coming from something on which you may or may not have as much control as other errors, like for
example if you have made a mistake in programming, or if your logic is wrong, those are not the kind
of errors which we are talking about when we talk about numerical methods.
So you're going to have two sources of error, which you are going to have. One is round-off error and
the other one is called truncation error. And let's go ahead and concentrate on what round-off error is.
Now round-off error is defined as follows, it is basically the error which comes from error created
due to approximate representation of numbers. So the round-off error is simply the error created by
the approximate representation of numbers, because in a computer you'll be able to only represent a
number only so approximately. For example, if you have a number like 1 divided by 3, and you had a
six significant digit computer let's suppose in the decimal notation, then this can be only approximated
as 0.333333 a simple rational number like 1 divided by 3 cannot be written exactly in the decimal format.
So the amount of round-off error which you are getting here is the difference between the value of 1
divided by 3 and the value of 0.333333. So in this case, this error is 0.0000003333 and so on and so
forth.
You're going to get similar round-off errors from other numbers also, like, you may have pi, that also
cannot be represented exactly, even in a decimal format, and then square root of 2, things like that.
So you're finding out there are many, many numbers, individual numbers, like 1 divided by 3, or pi, or
square root of 2, which cannot be represented exactly in a computer.
So that's why this creates the round-off error, the round-off error is the difference between what you
want to, what you want to be able to approximate, of what you want to be able to denote, and what you
are able to get as its approximation. So that's the, that's what we call as round-off error. So that's the
end of this particular segment here.
In this segment we're going to talk about truncation error. I want to say that we have sources of error in
numerical methods. And we're not talking about the errors which are created by writing the wrong
program, so far as logic or syntax is concerned, but the errors which are inherent when you are using
numerical methods, and one is called the round-off error, and the other one is called the truncation
error. So in this segment we're going to talk about, what does it mean when we say that, hey, we are
having a truncation error? So let's go ahead and write down the definite of truncation error.
Truncation error is defined as the error created by truncating a mathematical procedure
Now, some people don't like the word truncating in the definition of truncation error itself, because
they say that it doesn't mean much. So I'm going to cross it off there, and I'm going to say, hey,
approximating a mathematical procedure. So if you're going to approximate a mathematical procedure,
it is going to create some error, and that error is associated with truncation error. Please don't think
that truncation error is something which is associated with rounding off numbers. It is, truncation
error is related to the error which is created by approximating, not numbers, but a mathematical
procedure. Examples of truncation error as follows, so let's look at some examples. In this segment I'm
just going to enumerate the examples, and then we will have three more segments, which will show
each individual example with some numbers.
One of the examples is, let's suppose you are using Maclaurin series. The Maclaurin series for e to the
power x is 1 plus x plus x squared by factorial 2 plus x cubed by factorial 3, and plus so on and so forth.
So you have infinite number of terms in this particular series for e to the power x. So if you want to
calculate e to the power x at some value of x, let's suppose. And let's suppose if somebody says, hey,
calculate e to the power 0.5, so I would say 1 plus 0.5 plus 0.5 squared divided by 2 factorial plus 0.5
cubed, factorial 3, and so on and so forth. Now you can realize that since there are infinite terms in this
Maclaurin series to calculate e to the power 0.5, I don't have the privilege or the luxury to use all the
terms, all the infinite number of terms which I have in that particular series. If somebody were to say,
hey, I'm going to use only the first three terms of the series to calculate my value of e to the power 0.5.
So what's happening is that you are not accounting for these other infinite terms after the fourth term,
you're not accounting for those terms at all in your calculation e to the power 0.5, and whatever is
leftover is your truncation error. Because what you did was, the original mathematical procedure
required you to use infinite number of terms, but you are using only three terms, so whatever is leftover
is truncation error, because you have basically truncated a procedure, a mathematical procedure
requiring you to use infinite number of terms, and you're using only a few terms out of that . . . out of
that series there. Now what happens is that, in the past, I used to give only this as an example of
truncation error, and many students would think that truncation error is something which is only related
to series. But there are other examples where you will see how a mathematical procedure gets
truncated. So let's look at that.
For both types, the relationship between the exact, or true, result and the approximation can be
formulated as
Notice that for Eqs. (3.2) and (3.3), E and e are subscripted with a t to signify that the error is normalized
to the true value. In Example 3.1, we were provided with this value. However, in actual situations such
information is rarely available. For numerical methods, the true value will be known only when we deal
with functions that can be solved analytically. Such will typically be the case when we investigate the
theoretical behavior of a particular technique for simple systems. However, in real-world applications,
we will obviously not know the true answer a priori. For these situations, an alternative is to normalize
the error using the best available estimate of the true value, that is, to the approximation itself, as in
where the subscript a signifi es that the error is normalized to an approximate value. Note also that for
real-world applications, Eq. (3.2) cannot be used to calculate the error term for Eq. (3.4). One of the
challenges of numerical methods is to determine error estimates in the absence of knowledge regarding
the true value. For example, certain numerical methods use an iterative approach to compute answers.
In such an approach, a present approximation is made on the basis of a previous approximation. This
process is performed repeatedly, or iteratively, to successively compute (we hope) better and better
approximations. For such cases, the error is often estimated as the difference between previous and
current approximations. Thus, percent relative error is determined according to
Roots: Open Methods
Years ago, you learned to use the quadratic formula
The values calculated with Eq. (PT2.1) are called the “roots” of Eq. (PT2.2). They represent
the values of x that make Eq. (PT2.2) equal to zero. Thus, we can defi ne the root of an
4
y=3+4x -x
equation as the value of x that makes f ( x ) 5 0. For this reason, roots are sometimes
called the zeros of the equation. Although the quadratic formula is handy for solving Eq.
(PT2.2), there are many other functions for which the root cannot be determined so easily.
For these cases, the numerical methods described
1.5
0.5
x
1 2
Therefore there is a root (solution) to the equation 3 + 4 x − x 4 = 0 between x=1 and x=2.
If we want a better approximation we can narrow down the interval.
Let f ( x) = 3 + 4 x − x 4
then f (1) = 3 + 4 − 1 = 6 > 0
and f (2) = 3 + 8 − 16 = −5 < 0
therefore there is a root in the interval x=1 to x=2 y
0.6
0.4
0.2
x
1 1.5 2 2.5
-0.2
f (1.8) = - 0.2976 < 0 the root lies between 1.75 and 1.8
1.75 x 1.8
the root is 1.8 to 1 d.p
Example 2. Show that the equation ln(1 + x) − e − x − 1 = 0 has a root between x=1.5 and
x=2.5.
Find this root to 1 d.p.
Solution
Let f ( x) = ln(1 + x) − e − x − 1
f (1.5) = - 0.306 < 0
f (2.5) = 0.171 > 0 the root lies between 1.5 and
2.5
f (2.0) = - 0.0367 < 0 the root lies between 2.0 and
2.5
f ( 2.25) = 0.0732 > 0 the root lies between 2.0 and
2.25
f ( 2.1) = 0.009 > 0 the root lies between 2.0 and
2.1
f (2.05) = <0 the root lies between 2.05 and
2.1
2.05 x 2.1
the root is 2.1 to 1 d.p
Exercise
1. Show that x 3 = 14 has a root between 2 and 3. Find this root to 1dp.
2. Show that 2 x = 8 x has 2 roots, the first lying between 0 and 1 and the second
between 5 and 6. Find both of the roots to 1dp.
Answers
1. Let f ( x) = x 3 − 14
f (2) = 2 3 − 14 < 0
f (3) = 33 − 14 > 0 therefore root lies between 2 and 3
2.4 x 2.45
the root is 2.4 to 1 dp
2. Show that 2 x = 8 x has 2 roots, the first lying between 0 and 1 and the second
between 5 and 6. Find both of the roots to 1dp.
Let f ( x) = 2 x − 8 x
f (0) = 1 – 0 > 0
f(1) = 2 – 8 < 0 the root lies between 0 and 1
f(0.5) <0 the root lies between 0 and 0.5
f(0.25) <0 the root lies between 0 and0.25
f(0.1) > 0 the root lies between 0.1 and 0.25
f(0.2) < 0 the root lies between 0.1 and 0.2
f(0.15) <0 the root lies between 0 and 0.15
5.4 x 5.45
Example 1
Consider the equation x 2 − 5x + 2 = 0
y
15
10
y=x2 - 5x +2
5
x
-4 -2 2 4 6 8
-5
-10
Similarly
f(4) = 42 – 5(4) + 2 = -2 < 0
f(5) = 52 – 5(5) + 2 = 2 > 0
f(x) must be 0 between 4 and 5 and so the other solution lies between 4 and 5
we can now use this to get a sequence of solutions which get closer and closer to the root.
x = 4.56 to 2 dp
To find the other root, we need to re-arrange the equation x 2 − 5 x + 2 = 0 in a different way:
xn + 2
2
Let’s try x n +1 =
5
Let x0 = 4
then x1 =3.6
x2 =2.992
x3 = 2.1904128
x4 = 1.359581647
x5 = 0.76969245
x6 = 0.518485293
x7 = 0.4537654
x8 = 0.441180607
x9 = 0.438928065
x10 = 0.438531569
So how we arrange the equation and the starting value we choose can lead us to different
roots
x2 + 2
5x = x + 2
2
x = gives x = 0.44 (to 2 dp) ie the smaller root
5
2
Or x 2 = 5x − 2 x = 5− gives x = 4.56 to 2 dp
x
−2
Or x ( x − 5) = −2 x = gives x = 0.44 (to 2 dp) ie the smaller root
x−5
Some of the iteration formulae lead to the first root and some to the second root
Generally, when an equation has two or more roots, a single arrangement will not find them
all.
Each iteration formula may give only one root, so that for an equation with 3 roots, you may
need 3 iteration formulae, and so on.
Starting points for iteration
It saves time if you can use a starting point which is close to the root.
To do this, find an interval in which a root lies. That is find two values a and b such that
if f (a ) > 0 then f (b) < 0
The method converges for |g′(x)| < 1
Example 2
x n +1 = 2 + ln x n
x0 = 3
x1 = 3.098612289
x2 = 3.130954361
x3 = 3.141337866
x4 = 3.144648781
x5 = 3.145702209
x6 = 3.146037143
x7 = 3.146433611
x8 = 3.146177452
x9 = 3.146188209
x = 3.15 to 3 s.f.
[Link]
Exercise
1. Show that the equation x 3 − x − 2 = 0 has a root between 1 and 2, and can be arranged in
the form x = 3 x + 2 .
1
2
3
4
5
6
7
8
9
Matrices Part II
6. Transformation of matrices
7. The inverse of a 2×2 matrix
8. The determinant of a 2×2 matrix
9. Applications of matrices to solving two simultaneous
equations
10. The determinant of a 3×3 matrix, cofactors, minors
and adjoint
11. Properties of determinants
12. Inverse of a 3×3 Matrix
1
2
3
4
5
6
7
8
9
10
11
Solution of a system of simultaneous equations:
1
2
3
4
5
Method 3: Gaussian Jordan elimination
6
7
Curve Fitting Part I
Dr Jalil Kwad
University of Anbar
Department of civil Engineering
Introduction to Curve Fitting
Introduction Historians attribute the phrase regression analysis to Sir Francis Galton
(1822-1911), a British anthropologist and meteorologist, who used the term regression
in an address that was published in Nature in 1885. Galton used the term while talking
of his discovery that offspring of seeds “did not tend to resemble their parent seeds in
size, but to be always more mediocre [i.e., more average] than they.... The
experiments showed further that the mean filial regression towards mediocrity was
directly proportional to the parental deviation from it.” The content of Galton’s paper
would probably be called correlation analysis today, a term which he also coined.
However, the term regression soon was applied to situations other than Galton’s and
it has been used ever since. Regression Analysis refers to the study of the relationship
between a response (dependent) variable, Y, and one or more independent variables,
the X’s. When this relationship is reasonably approximated by a straight line, it is said
to be linear, and we talk of linear regression. When the relationship follows a curve,
we call it curvilinear regression. Usually, you assume that the independent variables
are measured exactly (without random error) while the dependent variable is
measured with random error. Frequently, this assumption is not completely true, but
when it cannot be justified, a much more complicated fitting procedure is required.
However, if the size of the measurement error in an independent variable is small
relative to the range of values of that variable, least squares regression analysis may
be used with legitimacy.
Given data for discrete values, derive a single curve that represents the
general trend of the data.
• Interpolation
Given data for discrete values, fit a curve or a series of curves that pass
directly through each of the points.
Dr Jalil Kwad
University of Anbar
Department of civil Engineering
Introduction to Curve Fitting
Introduction Historians attribute the phrase regression analysis to Sir Francis Galton
(1822-1911), a British anthropologist and meteorologist, who used the term regression
in an address that was published in Nature in 1885. Galton used the term while talking
of his discovery that offspring of seeds “did not tend to resemble their parent seeds in
size, but to be always more mediocre [i.e., more average] than they.... The
experiments showed further that the mean filial regression towards mediocrity was
directly proportional to the parental deviation from it.” The content of Galton’s paper
would probably be called correlation analysis today, a term which he also coined.
However, the term regression soon was applied to situations other than Galton’s and
it has been used ever since. Regression Analysis refers to the study of the relationship
between a response (dependent) variable, Y, and one or more independent variables,
the X’s. When this relationship is reasonably approximated by a straight line, it is said
to be linear, and we talk of linear regression. When the relationship follows a curve,
we call it curvilinear regression. Usually, you assume that the independent variables
are measured exactly (without random error) while the dependent variable is
measured with random error. Frequently, this assumption is not completely true, but
when it cannot be justified, a much more complicated fitting procedure is required.
However, if the size of the measurement error in an independent variable is small
relative to the range of values of that variable, least squares regression analysis may
be used with legitimacy.
Given data for discrete values, derive a single curve that represents the
general trend of the data.
• Interpolation
Given data for discrete values, fit a curve or a series of curves that pass
directly through each of the points.
2-Polynomial Regression
Some engineering data is poorly represented by a straight line. For these cases a curve is
better suited to fit the data. The least squares method can readily be extended to fit the data
to higher order polynomials.
Ex: Use the polynomial model to 𝑦 =𝑎0 + 𝑎1 𝑥 + 𝑎2 𝑥 2 to fit
3 6 20 𝑎0 72
6 20 72 𝑎1 = 224
20 72 272 𝑎2 808
7 6 20
224 20 72
𝑎0 = 808 72 272 = 5
3 6 20
6 20 72
20 72 272
3 72 20
6 224 72
𝑎1 = 20 808 272 = 7
3 6 20
6 20 72
20 72 272
3 6 72
6 20 224
20 72 808
𝑎0 = 3 6 20 = 0.75
6 20 72
20 72 272
Dr Jalil Kwad
University of Anbar
Department of civil Engineering
A- NEWTON’S DIVIDED-DIFFERENCE
INTERPOLATING POLYNOMIAL
As stated above, there are a variety of alternative forms for expressing
an interpolating polynomial. Newton’s divided-difference interpolating
polynomial is among the most popular and useful forms. Before
presenting the general equation, we will introduce the first- and second-
order versions because of their simple visual interpretation.
1- Linear Interpolation
The simplest form of interpolation is to connect two data points with a
straight line. This technique, called linear interpolation.
2- Quadratic Interpolation
An error maybe resulted from our approximating a curve with a straight
line. Consequently, a strategy for improving the estimate is to introduce
some curvature into the line connecting the points. If three data points
are available, this can be accomplished with a second-order polynomial
(also called a quadratic polynomial or a parabola.
Interpolation Part II
Dr Jalil Kwad
University of Anbar
Department of civil Engineering
A- NEWTON’S DIVIDED-DIFFERENCE
INTERPOLATING POLYNOMIAL
Dr Jalil Kwad
University of Anbar
Department of civil Engineering
The Newton-Cotes formulas are the most common numerical integration schemes.
They are based on the strategy of replacing a complicated function or tabulated
data with an approximating function that is easy to integrate.
Closed and open forms of the Newton-Cotes formulas are available. The closed
forms are those where the data points at the beginning and end of the limits of
integration are known. The open forms have integration limits that extend beyond
the range of the data.
Page 1 of 6
The difference between (a) closed and (b) open integration formulas.
Closed forum:
1- Trapezium Rule
Finding a definite integral can be thought of as determining the area under the
curve. Some integrals are difficult to evaluate exactly and so numerical methods
are needed.
Page 2 of 6
b
b−a
y dx 2 y0 + 2( y1 + y2 + ... + yn −1 )+ yn
h
where h =
a
n
Example
2 2
x3 23 1 7
.
1(i) Consider I = x dx = = − =
2
= 2. 3
1
3 1 3 3 3
2 −1
(ii) We have, using trapezium rule with 1 interval I
h
( y0 + y1 ) h= =1
2 1
x y =x2
y0 1 12
y1 2 22
I
2
(
1 2 2
1 +2 ) 1
= 5
2
= 2.5
Page 3 of 6
2 −1 1
(iii) Using 2 intervals: I
h
( y0 + 2 y1 + y2 ) h= =
2 2 2
x y =x2
y0 1 12
y1 3 2
3
2
2
y2 2 22
1
2
3
I 12 + 2 + 22
4 2
1 9
= 1 + + 4
4 2
19
=
8
= 2.375
2 −1 1
(iv) Using 4 intervals: I
h
( y0 + 2( y1 + y2 + y3 ) + y4 ) h= =
2 4 4
x y = x2
y0 1 12 =1
y1 5 2 =1.5625
5
4
4
y2 6 2 =2.25
6
4
4
y3 7 2 =3.0625
7
4
4
y4 2 22 =4
I
1
(1 + 2(1.5625 + 2.25 + 3.0625) + 4)
8
=
1
(18.75)
8
= 2.34375
Page 4 of 6
2π
3
2) Find the value of the integral sin( x) dx using the trapezium rule with
0
(i) 4 intervals (ii) 8 intervals giving your answers to 3 dp
i) with 4 intervals
x values sin(x)
0 y0 sin(0) 0.0000
π y1 π 0.7071
sin( )
6 6
2π y2 2π 0.9306
sin( )
6 6
3π y3 3π 1
sin( )
6 6
4π 2π y4 4π 0.9306
= sin( )
6 3 6
sin( x) dx
h
( y0 + 2( y1 + y 2 + y3 ) + y 4 )
0
2
π π
gives = 6 (0 + 2(0.7071+ 0.9306 + 1) + 0.9306) = 6
6.2060
2 2
=1.625 to 3dp
Page 5 of 6
ii) with 8 intervals
x values sin(x)
0 y0 sin(0) 0.0000
π y1 π 0.5087
sin( )
12 12
2π y2 π 0.7071
sin( )
12 6
3π y3 π 0.8409
sin( )
12 4
4π y4 π 0.9306
sin( )
12 3
5π y5 5π 0.9828
sin( )
12 12
6π y6 π 1
sin( )
12 2
7π y7 7π 0.9828
sin( )
12 12
8π 2π y8 8π 0.9306
= sin( )
12 3 12
( ( ) )
3
h
sin( x) dx
2
y 0 + 2 y1 + y 2 + y3 + y 4 + y5 + y 6 + y 7 + y8
0
gives =
π
12
(0 + 2(0.5087 + 0.7071+ 0.8409 + 0.9306 + 0.9828 + 1 + 0.9828) + 0.9306)
2
π
= 12
12.8364 =1.680 to 3dp
2
Page 6 of 6
Numrical Integration: applications
Dr Jalil Kwad
University of Anbar
Department of civil Engineering
The Newton-Cotes formulas are the most common numerical integration schemes.
They are based on the strategy of replacing a complicated function or tabulated
data with an approximating function that is easy to integrate.
Closed and open forms of the Newton-Cotes formulas are available. The closed
forms are those where the data points at the beginning and end of the limits of
integration are known. The open forms have integration limits that extend beyond
the range of the data.
Page 1 of 5
The difference between (a) closed and (b) open integration formulas.
Closed forum:
1- Trapezium Rule
2- SIMPSON’S RULES
Page 2 of 5
(a)Graphical depiction of Simpson’s 1/3 rule: It consists of taking the area
under a parabola connecting three points. (b) Graphical depiction of
Simpson’s 3/8 rule: It consists of taking the area under a cubic equation
connecting four points.
Page 3 of 5
As was done for the trapezoidal rule, Simpson’s 1y3 rule can be derived by
integrating the forward Newton-Gregory interpolating polynomial:
Page 4 of 5
Ex:
Page 5 of 5
Numrical Differentiation
Page 1 of 8
Page 2 of 8
Page 3 of 8
Page 4 of 8
Page 5 of 8
2- RICHARDSON EXTRAPOLATION
To this point, we have seen that there are two ways to improve derivative
estimates when employing finite divided differences: (1) decrease the step
size or (2) use a higher-order formula that employs more points. A third
approach, based on Richardson extrapolation, uses two derivative estimates
to compute a third, more accurate approximation.
Page 6 of 8
The previous example yielded a perfect result because the function being analyzed
was a fourth-order polynomial. The perfect outcome was due to the fact that
Richardson extrapolation is actually equivalent to fi tting a higher-order polynomial
through these data and then evaluating the derivatives by centered divided
differences. Thus, the present case matched the derivative of the fourth-order
Page 7 of 8
polynomial precisely. For most other functions, of course, this would not occur and
our derivative estimate would be improved.
but not perfect. Consequently, as was the case for the application of
Richardson extrapolation, the approach can be applied iteratively using a
Romberg algorithm until the result falls below an acceptable error criterion
Page 8 of 8
Ordinary Differential Equations
Dr Jalil Kwad
University of Anbar
Department of civil Engineering
Runge-Kutta Methods
EULER’S METHOD
PARTIAL DIFFERENTIAL
EQUATION:
Laplace’s equation
Page 1 of 9
Page 2 of 9
Page 3 of 9
Page 4 of 9
Page 5 of 9
Page 6 of 9
Page 7 of 9
Page 8 of 9
Page 9 of 9
Numerical Analysis References List
K. Atkinson: An Introduction to Numerical Analysis, Wiley, (2nd ed.),
1989.
P.G. Ciarlet and J. L. Lions (eds), Handbook of Numerical Analysis,
North Holland, 1990.
H. Keller: Analysis of Numerical Methods, Wiley, 1966
(or Dover 1994).
D. Kahaner, C. Moler, and S. Nash: Numerical Methods and Software,
Prentice-Hall, 1989.
D. Kincaid and W. Cheney: Numerical Analysis: Mathematics of
Scientific
Computing, American Mathematical Society, 3rd edition, 2001.
Solution of Nonlinear Systems of Equations and Optimization
J. E. Dennis and J. More: Quasi-Newton methods, motivation, and
theory,
SIAM Review, vol 19 #1, Jan. 1977.
J. E. Dennis and R. B. Schnabel: Numerical Methods for Unconstrained
Optimization and Nonlinear Equations, Prentice-Hall, 1983, SIAM,
1996.
Finite Difference Methods for Two-Point Boundary Value Problems and
Partial Differential Equations
S. K. Godunov and V. S. Ryabenki, Difference Schemes: an introduction
to the underlying theory, North Holland, 1987.
C. Grossmann, H-G. Roos, and M. Stynes: Numerical Treatment of
Partial
Equations, Second Edition, SIAM, 2004.
MATLAB
T. Davis and K. Sigmon: MATLAB Primer, Seventh Edition, Chapman
and Hall, 2004.
D. J. Higham and N. J. Higham: MATLAB Guide, Second Edition,
SIAM, 2005.