Docsity

Homework 3 Solutions for Computational Methods and Software | CS 417, Assignments of Computer Science

Toggle sidebar
bg1
CS 417/517 Computational Methods and Software
Spring 2004
Solutions to HW 3
Assigned: Thurs Feb 5, 2004; Due: Thurs Feb 12, 2004
Homework problems will be posted in the course directory:
www.cs.odu.edu/˜pothen/Courses/CS417. If any corrections are found to be neces-
sary, they will be posted in this directory as well. You must show your work to receive credit for
your answers. In problems where you are asked to give reasons, an answer without a stated reason
will receive no credit.
1. Apples = $0.29 ea, Bananas = $0.05 ea, Cantaloupes = $0.89 ea,
2. Matlab has a collection of ill-conditioned matrices that cause large errors in the computed
solution when floating point arithmetic is used. These matrices include magic,pascal,
hilb, etc. For this problem, let us investigate the n×nHilbert matrix H, whose elements
are given by
hij = 1/(i+j−1),for i= 1,2, . . . , n;j= 1,2, . . . , n.
(a) J = 1 : n; Creates a vector with elements being 1 through n.
J = J(ones(n,1) ,: ); Copies the J vector n times.
I = J; Creates a matrix I which is J transpose.
E = ones(n,n); Creates a matrix E which is n x n matrix of ones.
H=E./(I+J-1); Creates the Hilbert matrix by perform element by element divi-
sion.
(b) H = hilb(n); Creates a Hilbert matrix of order n.
b = sum(H,2); Creates a right hand side vector bsuch that the exact solution to Hx =b
is the vector of all ones.
x=H\bSolves the system of equations Hx =bin Matlab, x is shown in Figure 1.
(c) The difference between the computed solution and the exact solution e. The predict
errors e(n) = cond(hilb(n)) * eps, e(10) = 0.0036, e(20) = 424, e(30) = 1.3741e+003.
The errors is correctly predicted using e(n)
pf2

Partial preview of the text

Download Homework 3 Solutions for Computational Methods and Software | CS 417 and more Assignments Computer Science in PDF only on Docsity!

CS 417/517 Computational Methods and Software

Spring 2004 Solutions to HW 3 Assigned: Thurs Feb 5, 2004; Due: Thurs Feb 12, 2004

Homework problems will be posted in the course directory: www.cs.odu.edu/˜pothen/Courses/CS417. If any corrections are found to be neces- sary, they will be posted in this directory as well. You must show your work to receive credit for your answers. In problems where you are asked to give reasons, an answer without a stated reason will receive no credit.

  1. Apples = $0.29 ea, Bananas = $0.05 ea, Cantaloupes = $0.89 ea,
  2. Matlab has a collection of ill-conditioned matrices that cause large errors in the computed solution when floating point arithmetic is used. These matrices include magic, pascal, hilb, etc. For this problem, let us investigate the n × n Hilbert matrix H, whose elements are given by

hij = 1/(i + j − 1), for i = 1, 2 ,... , n; j = 1, 2 ,... , n.

(a) J = 1 : n; Creates a vector with elements being 1 through n. J = J(ones(n,1) ,: ); Copies the J vector n times. I = J; Creates a matrix I which is J transpose. E = ones(n,n); Creates a matrix E which is n x n matrix of ones. H = E. / (I + J - 1); Creates the Hilbert matrix by perform element by element divi- sion.

(b) H = hilb(n); Creates a Hilbert matrix of order n. b = sum(H,2); Creates a right hand side vector b such that the exact solution to Hx = b is the vector of all ones. x = H \ b Solves the system of equations Hx = b in Matlab, x is shown in Figure 1. (c) The difference between the computed solution and the exact solution e. The predict errors e(n) = cond(hilb(n)) * eps, e(10) = 0.0036, e(20) = 424, e(30) = 1.3741e+003. The errors is correctly predicted using e(n)

0 2 4 6 8 10

1

0 5 10 15 20

−

−

0

20

40

60

0 10 20 30

−

−

0

500

0 10 20 30 40

−

−

0

200

400

600

Figure 1: The values of x when Hilbert matrix sizes: n = 10, n = 20, n = 30 and n = 40.