关键词 > AMATH242/CS371

AMATH242/CS371 Spring 2023 Assignment I

发布时间:2023-05-30

Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

AMATH242/CS371 Spring 2023 Assignment I

Release date: Wednesday, May 10th

Due date: Friday, June 2nd, 11:59 pm

Due date with your one time extension: Wednesday, June 7th, 11:59 pm

• Questions below are either theoretical or computational. For the computational questions you may use any programming language you prefer except Maple or Mathematica.

• This assignment should be submitted to Crowdmark. Besides your written/typed solutions you must also submit your code. Please make sure your upload has the correct orientation and ordering.

• If you want to use your one time 3-day extension, please email the instructor before the original due date if you plan to use your extension.

1. (0 points) Please sign the Academic Integrity Checklist (found at the last page of this pdf). If you do not sign the Academic Integrity Checklist you will receive a 0 for this assignment.

2. (theoretical, 6 points) Consider a fictitious floating point number system F in a binary

computer with 1 bit for sign, 6 bits for mantissa and 4 bits for exponent.  An example of a

normalized number z in F may be: z = 1|010101|0110. We mimic single precision format and

reserve exponents (0000)2 and (1111)2 for special numbers ( ±zeros, ±infinities, etc.) and they

will NOT be used throughout this question. The rest of the exponents (0001)2  ≤ y ≤ (1110)2

are used to represent normalized numbers.  We further stipulate that the actual exponent

is computed by (y1 y2 y3 y4)2 − 7 so that there are negative exponents. You are now asked to answer the following questions:

(1) What is the range of the actual exponents (for normalized numbers in F)?

(2) The actual value z represents is as follows:  (−1)1 × (1.010101)2 × 2(0110)2 −7 .  Note that the red bit in front of the mantissa is not actually stored.  It’s assumed to be there for normalized numbers so that we don’t have to waste a mantissa bit for normalization. Compute this value in base 10.

(3) What is the largest and smallest positive normalized numbers that can be stored in F?

(4) What is the value of emaC h of F?

(5) What is the value of the unit roundoff u of F? Explain briefly what the value of u says about F .

(6) Give a decimal number which will cause floating point overflow when converted to the floating point system F .

3. (theoretical, 6 points) Let X = 4. Consider evaluating

z = X4 + 1                                                         (a)

using the floating point number system F as defined in Question 2. (Note that X is a floating point number in F .)

(1) Use a calculator to compute z . Would either X or z cause underflow or overflow in F? 


(2) If we use the floating point number system F in Question 2 to compute z with the formula eq. (a), do you foresee any issue? If so, can you derive another formula for z as a remedy? Briefly explain how your formula works.

(3) Use the floating point number system F to compute z using the formula derived in (2).

Show all your calculations.    Note that square root operation is usually considered as one of

the basic floating point arithmetic operations alongside with +, , ×, /. Thus the floating point approximation of, say, z = x should be

 = fl (4fl (x)) .

4. (computational, 6 points) The following MATLAB function computes an approximation to sin(x) using a truncation of its power series expansion sin(x) = x1 (−1)n+1 (2(x)n(2))! .

function  s  =  toy_ sin (x)

s  =  0;

t  =  x;

n  =   1;

while  s+t  ~=  s

s  =  s  +  t;

t  =  -x . ^2/(( n+1) *(n+2)) . *t;

n  =  n  +  2;

end

end

(1) The while loop terminates when S+t does not differ from S . Is this the same as continuing while t is not 0 (i.e. with the MATLAB expression t  ~=  0)?

(2) Modify function toy_sin so that it returns two more values - maxterm, the largest value of t during the execution of the function; and numterms, the number of terms of the power series used to calculate s.  Hence, the first line of your toy_sin .m should look like: function  [s, maxterm,  numterms]  =  toy_sin(x). Include a listing of this new toy_sin function in your submitted solution.

(3) Call the new toy_sin with x =  ,  ,  ,  . For each value of x, tabulate the values of s, maxterm and numterms and calculate the absolute value of the relative error in the computed sum for each x.

(4) Based on the table of your results, what can you conclude about the use of the toy_sin algorithm for various values of x?   Can you propose a way to improve toy_sin by

exploiting a special property of the sine function? (You DON’T have to implement this.)

5. (theoretical, 5 points) Consider the problem of evaluation the function f (x) = ln(x). Derive the expression for absolute and relative condition numbers, KA and KR, of the problem. Re- call that if KA and KR are“small”we can generally infer that the problem is well-conditioned. Are there any values of x such that the problem should NOT be considered well-conditioned?

6. (computational, 6 points) You’re asked in this question to calculate the root of ex  = 0. Include listings of the programs you implement for the following subquestions in your submitted solution.

(1) Write a program implementing the bisection algorithm in order to find the root. Choose a suitable initial interval [a, b] and briefly justify why the interval suits the bisection algorithm. Continue the iteration until the size of the interval is smaller than 1e-6.


(2) Write a program implementing Newton’s method to find the root. Choose a few initial guesses 0 < x0 < 5 and use a tolerance of 1e-6 on the size of the correction as the stopping criteria. Your program should print out an error message and exit in situations where Newton’s method becomes problematic. When ran successfully, your program output should include count of iteration steps.

(3) Implement the secant method with the same requirements in (2). You may use the same x0’s as in (2) with x1 = x0 + 1 to kick off the secant iteration. Compare iteration counts between secant method and Newton’s method and describe what you observe.

(4) When using an initial guess x0  ≤ −1 in (2), what do you observe from your program? Make a plot of ex −  and analyze why.