Docsity

Homework Set I for Numerical Methods | CS 257, Assignments of Computer Science

Toggle sidebar
bg1
CS 257: Numerical Methods
Spring 2006
Homework, Set 1 Due Thursday January 26, 2006
Write descriptive solutions. Comment your code!
(1) (NMM Ch. 2 #5) Use the linspace function to create vectors identical to those obtained with the
statements that follow. Use multiple statements where necessary. (Use MATLAB’s built-in norm
function to test whether two vectors are equal without printing the elements.)
(a) x = 0 : 10
(b) x = 0 : 0.2 : 10
(c) x = -12 : 12
(d) x = 10 : -1 : 1
(2) (NMM Ch. 2 #14) Use the diag function to create the symmetric, n×n, tridiagonal matrix
D=
2−1 0 0
−1 2 −1 0
0−1 2 −1
0 0 −1 2
(Hint: The two parameter form of diag will be helpful.)
(3) (NMM Ch. 2 #16) Write a one-line expression to create the following matrix:
10001
−1 1 0 0 1
−1−1 1 0 1
−1−1−111
−1−1−1−1 1
(Hint: One solution uses matrix addition and the built-in tril,ones,eye, and zeros commands.)
(4) (NMM Ch. 2 #29) A theoretical model of an athlete in a sprint race is (see W.G. Pritchard, Mathe-
matical Models of Running, SIAM Review, Vol. 35, No. 3, pp. 359-379, September 1993)
x(t) = aτ[t−τ(1 −e−t/τ )]
where xis distance traveled in time t, and aand τare constants for a given runner and distance of
the race. Measured values of x(t) for Carl Lewis and Ben Johnson in 100-meter final at the 1987
Championship in Rome are given in the following table:
x(m) 0 10 20 30 40 50 60 70 80 90 100
Lewis time(s) 0 1.94 2.96 3.91 4.78 5.64 6.50 7.36 8.22 9.07 9.93
Johnson time(s) 0 1.84 2.86 3.80 4.67 5.53 6.38 7.23 8.10 8.96 9.83
A curve fit to Lewis data gives τ= 0.739 sand a= 14.4m/s2. Plot the measured times for Lewis
and Johnson versus the theoretical model of Carl Lewis on the same graph. Use a solid line for
theoretical model, and use symbols with no line for the measured data. To make the theoretical
curve look smooth at small times, choose a small time increment, say, 0.2 s. Label the axes and add
a legend to the plot.
Get file sprint.dat from here
http://www.cs.uiuc.edu/class/sp06/cs257/homework/sprint.dat
pf2

Partial preview of the text

Download Homework Set I for Numerical Methods | CS 257 and more Assignments Computer Science in PDF only on Docsity!

CS 257: Numerical Methods Spring 2006 Homework, Set 1 Due Thursday January 26, 2006

Write descriptive solutions. Comment your code!

(1) (NMM Ch. 2 #5) Use the linspace function to create vectors identical to those obtained with the

statements that follow. Use multiple statements where necessary. (Use MATLAB’s built-in norm

function to test whether two vectors are equal without printing the elements.) (a) x = 0 : 10 (b) x = 0 : 0.2 : 10 (c) x = -12 : 12 (d) x = 10 : -1 : 1

(2) (NMM Ch. 2 #14) Use the diag function to create the symmetric, n × n, tridiagonal matrix

D =

(Hint: The two parameter form of diag will be helpful.)

(3) (NMM Ch. 2 #16) Write a one-line expression to create the following matrix:    

(Hint: One solution uses matrix addition and the built-in tril, ones, eye, and zeros commands.)

(4) (NMM Ch. 2 #29) A theoretical model of an athlete in a sprint race is (see W.G. Pritchard, Mathe- matical Models of Running, SIAM Review, Vol. 35, No. 3, pp. 359-379, September 1993)

x(t) = aτ [t − τ (1 − e−t/τ^ )] where x is distance traveled in time t, and a and τ are constants for a given runner and distance of the race. Measured values of x(t) for Carl Lewis and Ben Johnson in 100-meter final at the 1987 Championship in Rome are given in the following table: x(m) 0 10 20 30 40 50 60 70 80 90 100 Lewis time(s) 0 1. 94 2. 96 3. 91 4. 78 5. 64 6. 50 7. 36 8. 22 9. 07 9. 93 Johnson time(s) 0 1. 84 2. 86 3. 80 4. 67 5. 53 6. 38 7. 23 8. 10 8. 96 9. 83

A curve fit to Lewis data gives τ = 0. 739 s and a = 14. 4 m/s^2. Plot the measured times for Lewis and Johnson versus the theoretical model of Carl Lewis on the same graph. Use a solid line for theoretical model, and use symbols with no line for the measured data. To make the theoretical curve look smooth at small times, choose a small time increment, say, 0.2 s. Label the axes and add a legend to the plot. Get file sprint.dat from here http://www.cs.uiuc.edu/class/sp06/cs257/homework/sprint.dat

(5) (NMM Ch. 2 #33) Surface plots do not need to be plot on a rectangular grid. Create a surface plot of z = 2 + x^2 + y^2 defined on the domain bounded by the circle x^2 + y^2 = 5. The trick is to evaluate the

function at points inside the circle. MATLAB’s plotting routines will do the hard work. First define

the r and θ vectors with

r = linspace(0,sqrt(5),20); theta = linspace(0,2*pi,10)

Then evaluate the X and Y matrices with outer products

Xi,j = ri cos(Θj ) and Yi,j = ri sin(Θj )

The surface function Z = f (X, Y ) is evaluated just as in Example 2.7. Contrast the resulting plot from that obtained when X and Y result from

x = linspace(-5,5,20); [X,Y] = meshgrid(x,x);

(6) Show that

n= 1 (2n+1)(2n+2) converges to log (2) (the^ natural^ log). Do not use loops.