COMPUTER SCIENCE ASSIGNMENT #2 Solution

$30.00

Description

This is a really large class and the logistics of grading assignments are challenging. Me and the markers require your help in making this process go smoothly. Please ensure that your assignments conform to the following requirements – any violation will result in getting a zero for the particular assignment.

All assignments should be submitted electronically through the ConneX course website and shoud be SINGLE PDF FILES. No other formats will be accepted.. Handwrit-ten answers are ok but they will need to be scanned and merged into a single pdf le together with any code examples and associated plots.

The assignment number, student name and student number should be clearly visible on the top of every page of your assignment submission.

PLEASE DO NOT COPY THE ASSIGNMENT DESCRIPTION IN YOUR SUBMISSION

The asnwers to the questions should be in the same order as in the assignment speci-cation.

Some of the questions of the assignments are recycled from previous years but typically with small changes in either the description or the numbers. Any submission that contains numbers from previous years in any questions will be immediately graded with zero.

Any assignment related email questions should have a subject line of the form CSC349A Assignment X, where X is the number of the corresponding assignment.

The total number of points for this assignment is 20.

Question #1 – 8 marks.

Consider a base 5 normalized, oating-point number system. Assume that a hypothetical computer using this system has the following oating-point representation:

sm f1 f2 f3 f4 se e1 e2

where sm is the sign of the mantissa, se is the sign of the exponent (1 for negative, 0 for positive), fi are the digits of the mantissa, and ej are the digits of the exponent.

  1. Consider the base 5 number, given using the above representation, 02003004. What exact decicaml value does it represent?

  1. What decimal value does 11004003 represent?

  1. What is the smallest positive, non-zero, number that can be represented in this system? Give the answer in the above form (i.e. as 8 base-5 digits.) and in decimal.

  1. What is the size of the gap between any two consecutive numbers in the interval 25(10) and 125(10) in this oating-point representation system? Your answer should be in decimal.

Question #2 – 6 Marks.

The polynomial P (x) = x2 83:12x + 3:123 has two roots, at approximately 0:0375892

and 83:0824. The roots of a quadratic polynomial ax2 + bx + c can be computed by p

(i)

b b2 4ac

or equivalently (ii)

2c

2a

b pb2 4ac

Using oating-point arithmetic, one of these formulas is often much more accurate than p

the other. For example, if ( b + b2 4ac)=(2a) is used to compute one of the roots of P (x) = x2 83:12x + 3:123 = 0 with base b = 10 , precision k = 4, idealized chopping arithmetic, the results are as follows:

(b2) = (()6908:9344) = 6908 or 0:6908 104:

(4a) = 4 or 0:4000 101:

(4ac) = (4 3:123) = (12:492) = 12:49

(b2 4ac) = (()6908 12:49) = (()6895:51) = 6895

p p

( b2 4ac) = ( 6895) = (83:036136 ) = 83:03

p

( b + b2 4ac) = (83:12 + 83:03) = (166:15) = 166:1

(2a) = 2

p

b + b24ac = 166:1 = 83:05 or 0:8305 102

2a2

which is very accurate. The relative error is about 0:00039 or 0:039%.

On the other hand, it can be shown (similar to the above) that

b +

pb24ac

2c

= 69:40 or 0:6940

102

which (using the exact value of 83:0824 ) has a large relative error of 0:165 or 16:5%.

  1. Use base b = 10, precision k = 4, idealized chopping arithmetic and each of the mathematically equivalent formulas

b p

2c

and

b2 4ac

b pb2 4ac

2a

to compute an approximation to one root of P (x) = 1:2x2 78:99x + 1:234 = 0. As above, specify each step of the computation. Note that many of the computations for the two formulas are identical, and need only be done once. Use your calculator to do this, not MATLAB.

  1. Compute the relative errors of each of the approximations in (a) using the fact that the exact value of the root is 0:01562594 . Give at least 2 signi cant digits.

  1. One of the two zeros of a quadratic polynomial ax2 + bx + c can be computed using either the formula

b + p

(i)

b2 4ac

or (ii)

2c

2a

b + pb2 4ac

For each of the speci ed polynomials in the table below, place an X in the appropriate box to indicate which of these formulas is more accurate in precision k = 4 oating-point arithmetic. Put exactly one X in each row of the table. (No justi cation for your answers is required. It is NOT necessary to do any oating-point computation to answer this question.)

polynomial

(i) is more accurate

(ii) is more accurate

0:01x2 125x + 0:05

0:3x2 + 125x + 0:025

Question #3 – 6 Marks

p

(a) Determine the second order (n = 2) Taylor series expansion for f(x) = x + 3 ex-panded about a = 1 including the remainder term. Leave your answer in terms of factors (x 1) (that is, do not simplify). Show all your work.

  1. Use the polynomial approximation in (a) (without the remainder term) to approximate p

f(1:12) = 4:12. Use either hand computation, your calculator or MATLAB. Give an exact answer.

  1. Determine a good upper bound for the truncation error of the Taylor polynomial

approximation in (a) for all values of x such that 1 x 1:2 by bounding the remainder term.

4