Vous êtes sur la page 1sur 3

KE36903 Numerical Methods

Assignment 1
Due Date: 12 October 2015
Question No. 1
The following Matlab code evaluates mean and variance, using the chop
function to simulate a machine with a precision of 6 decimal digits.
>> n = length(x);
>> sum1 = 0;
>> sum2 = 0;
>> for i=1:n
sum1 = chop(sum1 + x(i)^2, 6);
sum2 = chop(sum2 + x(i), 6);
end;
>> samplemean = chop(sum2/n, 6)
>> samplevariance = chop((sum1 - sum2^2/n)/(n-1), 6)

If we run this code with input vector


x = [ 1002 1000 1003 1001 1002 1002 1001 1004 1002 1001 ]
it returns
samplemean =
1.0018e+003
samplevariance =
-3.6000
This is clearly wrong, because the variance must be a nonnegative
number. (The correct answer is = 1001.8, s2 = 1.2889.)

Explain why the result is wrong.


How would you compute the sample variance more accurately,
without increasing the number of correct digits in the calculation
(i.e., if you still round all the intermediate results to 6 decimal
digits)?

Question No. 2
A computer uses a toy floating point number system using a ternary Russian
computer. The number system uses three trits (which can store 0, 1, or 2)
for the mantissa and the convention that the 1-trit is on the left of the
decimal point (i.e. the mantissa represents the base 3 real number:
[d1.d2d3]3). It uses two trits for the exponent.

What is realmax (overflow) and realmin (underflow) in the toy system?


Give your answers in base 10 number.
What is the machine precision (eps) in the toy system assuming
rounding by chopping rule is used?
For some value of x, show that the following expression will lose
accuracy when it is evaluated in the toy floating point number system.
Rewrite the expression so that accuracy will not be lost. Justify that the
equivalent expression will avoid a loss of significance.

Question No. 3
In the computer architecture class, Alex has created a computer that runs on
a normalized floating-point number system with a 3-digit mantissa and a 1digit exponent. The system uses round-to-nearest rounding rule. The
following questions are solved using this computer.

Determine how many different numbers than can be represented in the


range [, 4].
For some small value of x, show that the following expression will lose
accuracy when it is evaluated in floating point number.
Rewrite the expression in (b) so that accuracy will not be lost.

Question No. 4
You can evaluate y = (I + uvT )x where u, v, x are n-vectors in two ways:

A = I + uvT followed by y = Ax (in Matlab: y = (eye(n)+u*v)*x)

w = (vT x)u followed by y = x + w (in Matlab: y = x + (v*x)*u)

Both methods give the same answer, but which method is faster?
(Note that I is an identity matrix)
Question No. 5
Consider the matrix:

Obtain the LU factorization of matrix A. Work with a normalized floatingpoint system with a 3-digit mantissa.

Determine how many suspect digits due to round-off error would be


generated if the floating-point system described in (a) is used.

Question No. 6
The following system of equations is used by Dr. Siva to determine
concentrations in a series of coupled reactors as a function of the amount of
mass input to each reactor:

Prove that a set of solutions to c1, c2, and c3 exists and is unique.
Rewrite the equation in the form of AX = b and hence obtain the LU
factorization of the matrix A. Work with a normalized floating-point
system with a 3-digit mantissa.
Explain briefly how you are going to find the inverse of the matrix A by
numerical methods. Show your method by determining only the first
column of the inverse of the matrix A.

Question No. 7
Given that the parabola passes through the coordinates (1, 4), (2, 7) and (3,
14).

Write the necessary equations in Ax = b form.


Obtain the LU factorization for matrix A.
Determine the unknown coefficients A, B and C.
Determine whether matrix A is well-conditioned.

Vous aimerez peut-être aussi