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

MAT005 Lab Exercise 3

The document demonstrates how round-off and truncation errors are generated using MATLAB. It shows an example of round-off errors occurring when calculating solutions to a quadratic equation. It also provides an example of truncation errors when numerically evaluating a function using a Taylor series with a finite number of terms.

Uploaded by

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

MAT005 Lab Exercise 3

The document demonstrates how round-off and truncation errors are generated using MATLAB. It shows an example of round-off errors occurring when calculating solutions to a quadratic equation. It also provides an example of truncation errors when numerically evaluating a function using a Taylor series with a finite number of terms.

Uploaded by

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

Laboratory Exercise No.

Round-off and Truncation Errors

Objectives:

1. Demonstrate how round-off and truncation errors are generated using MATLAB
2. Calculate the round-off and truncation errors using MATLAB

Materials and Equipment:

1 unit Computer with an installed MATLAB software and internet connection

Demonstration:

1. The magnitude of round-off errors depends on the magnitude of the numbers that are
involved since the interval between the numbers that can be represented on a computer
depends on their magnitude. Round-off errors are likely to occur when the numbers that
are involved in the calculations differ significantly in their magnitude and when two numbers
that are nearly identical are subtracted from each other. For example, consider the
quadratic equation:

for which the exact solutions are x1 = 100 and x2 = 0.0001. The solutions can be calculated
with the quadratic formula:

Using MATLAB (Command Window) to calculate x1 and x2 gives:

>> format long


>> a = 1; b = -100.0001; c = 0.01;
>> RootDis = sqrt(b^2 - 4*a*c)

RootDis =

99.999899999999997

>> xl = (-b + RootDis)/(2*a)

xl =

100

>> x2 = (-b - RootDis)/(2*a)

x2 =

1.000000000033197e-04
The value that is calculated by MATLAB for x2 is not exact due to round-off errors.
Calculating the round-off error (re) for x2 in MATLAB, the result is:

>> re = 0.0001 - x2

re =

-3.319650869297586e-15

The round-off error occurs in the numerator in the expression for x2 Since b is negative, the
numerator involves subtraction of two numbers that are nearly equal. In many cases, the
form of the mathematical expressions that contain subtraction of two quantities that are
nearly equal can be changed to a different form that is less likely to cause round-off errors.
In the expression for x2, this can be done by multiplying the expression by

Using this result in MATLAB to calculate the value of x2 gives:

>> x2Mod = (2*c)/(-b+RootDis)

x2Mod =

1.000000000000000e-04

Calculating the round-off error (re) for x2 in MATLAB, the result is:

>> re = 0.0001 - x2Mod

re =

2. Truncation errors occur when the numerical methods used for solving a mathematical
problem use an approximate mathematical procedure. A simple example is the numerical
evaluation of sin(x), which can be done by using Taylor's series expansion

The value of sin (π/6) can be determined exactly with the equation above if an infinite
number of terms are used. The value can be approximated by using only a finite number
of terms. The difference between the true (exact) value and an approximate value is the
truncation error, denoted by ETR. For example, if only the first term is used:
If two terms of the Taylor's series are used:

In MATLAB, we can calculate the exact value of sin (π/6), the truncated value (tv) up to
three terms, and the truncation error (te) as follows:

>> sin(pi/6)
ans =
0.500000000000000
>> x = pi/6;
>> tv = x - x^3/(3*2*1)+ x^5/(5*4*3*2*1)
tv =
0.500002132588792
>> te = sin(pi/6) - tv
te =
-2.132588792502776e-06

Exercises:

a. Consider the function:

Use MATLAB to calculate the value of f(x) (use the variable name fx) for x = 1000.
(2 points)

b. Multiplying the right-hand side of the function in item (a) by gives

Use this result to calculate an improved value of the function f(x) (use the variable
name fxmod) and calculate the round-off error (use the variable name re) which is
equal to the difference fxmod - fx. (3 points)

c. Use MATLAB to calculate the value of cos (π/4) (use the variable name cosx). Then,
use the Taylor’s series expansion of f(x) = cos x, as shown below, to calculate a
truncated estimate or value for cos (π/4) using up to three terms only of the series (use
the variable name cosxt).

Lastly, calculate the truncation error or the difference cosx – cosxt (use the variable
name te). (5 points.)

------------------------------------------NOTHING FOLLOWS------------------------------------------

You might also like