Docsity

AMSC/CMSC 460 Assignment #1: Numerical Computing with MATLAB - Prof. Peter Wolfe, Assignments of Computer Science

Toggle sidebar
bg1
AMSC/CMSC 460 Dr. Wolfe ASSIGNMENT #1 Due June 12, 2009
1. Ex.1.35, p.46, Numerical Computing with MATLAB . Modify the programs by insert-
ing a counter that will count the lines of output. Do not hand in any output. Just
answer the questions.
2. Ex.1.38, p.46, Numerical Computing with MATLAB
3. Ex.1.39, p.47, Numerical Computing with MATLAB Explain, using a fundamental
property of the sine function, how one could modify powersin so it would compute
sin xaccurately for all real x.
4. 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).
5. For a set of measurements x1, x2,...,xN, the sample mean ¯xis defined to be
¯x=1
N
N
X
i=1
xi.
The sample standard deviation sis defined to be
(N−1)s2=
N
X
i=1
(xi−¯x)2.
Another expression,
(N−1)s2=
N
X
i=1
x2
i−1
N
N
X
i=1
xi2
,
is ofter recommended for hand computation of s. Show that these two expressions
for sare mathematically equivalent. Explain why one of them may provide better
numerical results than the other, and construct and example to illustrate your point.
6. 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
pf2

Partial preview of the text

Download AMSC/CMSC 460 Assignment #1: Numerical Computing with MATLAB - Prof. Peter Wolfe and more Assignments Computer Science in PDF only on Docsity!

AMSC/CMSC 460 Dr. Wolfe ASSIGNMENT #1 Due June 12, 2009

  1. Ex.1.35, p.46, Numerical Computing with MATLAB. Modify the programs by insert- ing a counter that will count the lines of output. Do not hand in any output. Just answer the questions.

  2. Ex.1.38, p.46, Numerical Computing with MATLAB

  3. Ex.1.39, p.47, Numerical Computing with MATLAB Explain, using a fundamental property of the sine function, how one could modify powersin so it would compute sin x accurately for all real x.

  4. 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

  5. 3 ⊕ 57 .4 = 107.

Define machine multiplication x ⊗ y similarly. 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).

  1. For a set of measurements x 1 , x 2 ,... , xN , the sample mean ¯x is defined to be

x¯ =

N

∑^ N

i=

xi.

The sample standard deviation s is defined to be

(N − 1)s^2 =

∑^ N

i=

(xi − x¯)^2.

Another expression,

(N − 1)s^2 =

∑^ N

i=

x^2 i −

N

( ∑N

i=

xi

is ofter recommended for hand computation of s. Show that these two expressions for s are mathematically equivalent. Explain why one of them may provide better numerical results than the other, and construct and example to illustrate your point.

  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 .113731041e + 5. (e+n means 10n.) 0.1673e+0 0.3875e+1 0.8053e+ 0.2548e+0 0.5478e+2 0.8886e+ 0.2997e+1 0.7113e+2 0.9546e+

  1. Let f (x) =

ln(1 + x) − sin x − cos x + 1 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. Write a program to compute the first 60 terms in the sequence given by the difference equation xk+1 = 2. 25 xk − 0. 5 xk− 1 (1)

with the starting values x 1 =

and x 2 =

Make a plot of log 2 xk (log2 in MATLAB) as a function of k. The exact solution of (1) is given by

xk =

41 −k 3 which decreases monotonically as k increases. Does your graph confirm this theo- retically expected behavior? Can you explain the results? (Hint: Find the general solution of (1). To do this, look for solutions of the form xk = αk^ and observe that (1) is linear.)

  1. For α = 0.8717 and β = 0.8719 calculate the midpoint m of the interval [α, β] by using the formula m = (α + β)/2. First use four-digit decimal chopped arithmetic, then four digit rounded arithmetic. How reasonable are the answers? Find another formula for the midpoint and use four-digit decimal (rounded or chopped) arithmetic to calculate the midpoint of [0. 8717 , 0 .8719]. Is your formula better or worse?
  2. What is the nearest floating point number to 64 on a base-2 computer with 5-bit mantissas? Show work.