Docsity

Computational Methods - Assignment 1 - Fall 2001 | MAPL 460, Assignments of Mathematics

Toggle sidebar
bg1
CMSC/MAPL 460 Dr. Wolfe ASSIGNMENT #1 Due February 19, 2001
1. Run the following MATLAB programs and explain the output.
x= 1; x= 1; x= 1;
while x+ 1 >1 while x > 0 while x <Inf
y=x;y=x;y=x;
x=x/2; x=x/2; x= 2 ∗x;
end end end
yyy
Assume β= 2. What can you infer about the machine constants t, U and L? (The
last two constants are called Mand min Shampine et al.)
2. Using four digit arithmetic, add the following numbers, first in ascending order (from
smallest to largest) and then in descending order. In doing so round off the partial
sums to four significant figures. Compare your results with the correct sum x=
0.107101023 E5. (En means 10n.)
0.1580 E0 0.4288 E1 0.7767 E3
0.2653 E0 0.6266 E2 0.7889 E3
0.2581 E1 0.7555 E2 0.8999 E4
3. Let
f(x) = ln(1 −x) + xex/2
x3.
Use MATLAB to compute f(x) for x= 10−m, m = 1,2,· ·· ,12. According to the
theory what is limx→0f(x) ? For xnear zero what is a better way to compute f(x)
? (Hint: Use Taylor’s theorem on the numerator.)
4. How can values of the function f(x) = √x+ 2 −√xbe computed accurately when x
is large ?
5. Suppose a computer carries three decimal digits and rounds. If xand yare machine
numbers, define the machine version of addition x⊕yto be the result of adding xand
yand rounding to three digits. For example
49.3⊕57.4 = 107.
Define machine multiplication x⊗ysimilarly. For example,
1.23 ⊗4.86 = 5.98.
Constuct examples to show that, in general, the following statements are not true:
(a) (x⊕y)⊕z=x⊕(y⊕z),
(b) (x⊗y)⊗z=x⊗(y⊗z),
(c) x⊗(y⊕z) = (x⊗y)⊕(x⊗z).
pf2

Partial preview of the text

Download Computational Methods - Assignment 1 - Fall 2001 | MAPL 460 and more Assignments Mathematics in PDF only on Docsity!

CMSC/MAPL 460 Dr. Wolfe ASSIGNMENT #1 Due February 19, 2001

  1. Run the following MATLAB programs and explain the output. x = 1; x = 1; x = 1; while x + 1 > 1 while x > 0 while x <Inf y = x; y = x; y = x; x = x/2; x = x/2; x = 2 ∗ x; end end end y y y

Assume β = 2. What can you infer about the machine constants t, U and L? (The last two constants are called M and m in Shampine et al.)

  1. Using four digit arithmetic, add the following numbers, first in ascending order (from smallest to largest) and then in descending order. In doing so round off the partial sums to four significant figures. Compare your results with the correct sum x = 0 .107101023 E5. (En means 10n.) 0.1580 E0 0.4288 E1 0.7767 E 0.2653 E0 0.6266 E2 0.7889 E 0.2581 E1 0.7555 E2 0.8999 E
  2. Let f (x) =

ln(1 − x) + xex/^2 x^3

Use MATLAB to compute f (x) for x = 10−m, m = 1, 2 , · · · , 12. According to the theory what is limx→ 0 f (x)? For x near zero what is a better way to compute f (x) ? (Hint: Use Taylor’s theorem on the numerator.)

  1. How can values of the function f (x) =

x + 2 −

x be computed accurately when x is large?

  1. Suppose a computer carries three decimal digits and rounds. If x and y are machine numbers, define the machine version of addition x ⊕ y to be the result of adding x and y and rounding to three digits. For example

Define machine multiplication x ⊗ y similarly. For example,

Constuct examples to show that, in general, the following statements are not true: (a) (x ⊕ y) ⊕ z = x ⊕ (y ⊕ z), (b) (x ⊗ y) ⊗ z = x ⊗ (y ⊗ z), (c) x ⊗ (y ⊕ z) = (x ⊗ y) ⊕ (x ⊗ z).

  1. The error function is an important function in many branches of applied mathe- matics. It is defined by an integral.

erf(x) =

π

∫ (^) x

0

exp(−t^2 ) dt.

The integral cannot be expressed in terms of more elementary functions. It is a library function in MATLAB. The Taylor series for the error function is

erf(x) =

π

∑^ ∞

n=

(−1)nx^2 n+ n!(2n + 1)

The series converges for all x. Write a MATLAB function m-file to evaluate erf(x) using this series. Use as many terms in the series as are necessary so that the first neglected term does not alter the accumulated sum when it is added to it in floating point arithmetic. Since this is an alternating series, the error caused by truncating the infinite sum will then be less than the roundoff error. Investigate the effect of roundoff error by comparing the computed sum with the value given by the MATLAB function erf. Try x = 0. 5 , 1. 0 , 2. 0 , 5. 0 , 7. 0 , 10 .0. Explain your results. Hint: The main loop of your program might look like this: while s ∼= so so = s; n = n + 1; t = −xsq ∗ t ∗ (2. 0 ∗ n − 1 .0)/(n ∗ (2 ∗ n + 1)); s = s + t; end What values should be assigned to t, n, s and xsq before entering the loop? Do not forget the factor 2/

π.

  1. Ex. 1.2, p.11, Shampine, Allen & Pruess
  2. Ex. 1.9, p.23, Shampine, Allen & Pruess
  3. Ex. 1.16, p.29, Shampine, Allen & Pruess