matlab latex代写-CSC336S-Assignment 2
时间:2022-03-01
CSC336S Assignment 2 Due Thursday, March 10, 2022
Please write your family and given names and underline your family name on the front page of your paper.
Answers must be typed (preferably in latex), and compiled to a single pdf. Code, output and plot of Q3 should be embedded
in latex/pdf. Code and output should be embedded with fixed-width fonts, e.g. Courier. Font size of all fonts must
be 12. Linespacing set to 1.1 or close. Do not use dark backgrounds at any point of the pdf file.
Submit the single pdf file 00A2.pdf (with embedded code, output and plots), as well as your code and output. Thus, the code
will be available within latex/pdf, as well as separately. Do not submit zip files.
See course website for example of latex, embedding plots, code, using fixed width fonts, etc.
Some points will be given for the quality of presentation.
General
note: Plotting quantity y versus quantity x, means that x is in the
x-axis and y is on the y-axis, i.e. what follows "ver-
sus" is in the horizontal axis.
1. Consider the matrix A and its inverse A−1,
A =
6
13
−17
13
29
−38
−17
−38
50
A−1 =
6
−4
−1
−4
11
7
−1
7
5
.
(a) [3 points] What is the condition number of A in the infinity norm?
(b) [6 points] Suppose we solve Ax = b for some b, and obtain xˆ, so that ||b − Axˆ||
∞
≤ 0. 01. How small an upper bound
can be found for the absolute error ||x − xˆ||
∞
? Giv e the bound as a numerical value.
(c)
[6 points] With the same situation as in (b), how small an upper bound
can be found for the relative error || ˆx − x||∞||x||
∞
?
Give the bound in terms of ||b||
∞
.
2. [30 points] Consider the linear system
0. 00211x1 + 0. 08204x2 = 0. 04313
0. 337x1 + 12. 84x2 = 6. 757
Solve the system using Gauss elimination and applying 4-decimal-digits floating-point arithmetic with proper round-
ing. The results of each operation (addition, multiplication, division) of GE must be stored using 4-decimal-digits
floating-point representation. Do this three times: (a) without pivoting, (b) with partial pivoting, (c) with complete piv-
oting. Indicate the intermediate results (multipliers, upper triangular matrix), and xˆ for each case.
In each of the three cases, what are the relative errors (in abs. value) for each component of x = (x1, x2)T , and what are
the relative errors for x in the infinity norm and in the one-norm? (That is, what are |x1 − xˆ1||x1| ,
|x2 − xˆ2|
|x2| ,
||x − xˆ||
∞
||x||
∞
,
and
||x − xˆ||1
||x||1 ?) Present the errors in table form (three cases as rows, and four errors as columns), and comment. Exact
solution is (1. 000, 0. 500)T .
3. [30 points] Giv en a set of points xi , i = 1, . . . , n, usually equidistant, the corresponding Vandermonde matrix is the
following n × n matrix:
1
1
.
1
x1
x2
.
xn
.
.
.
.
xn−11
xn−12
.
xn−1n
The Vandermonde matrices can be shown to be non-singular for any n, iff the points xi , i = 1, . . . , n, are distinct. How-
ev er, the Vandermonde matrices are known to be ill-conditioned for large n. In this problem, we study how the condi-
tion number of a Vandermonde matrix increases with n, and how this affects the accuracy of the solution of a system
with a Vandermonde matrix.
Write a MATLAB script which, for n = 4, . . . , 19, (i) generates the Vandermonde matrix corresponding to n equidistant
points covering [0, 1], (ii) computes its condition number in the Euclidean norm, (iii) solves a system with this matrix
and a right side chosen so that the solution to the system is a vector of 1’s and length n, (iv) estimates the relative error
in the computed solution, using Euclidean norm, and (v) outputs n, the condition numbers and errors in the form of a
CSC336 Assignment 2 C. Christara
- 2 -
table (each row corresponds to a value of n and columns are aligned). Use fprintf(’%2d %9.2e %9.2e\n’,
n, c(n-3), e(n-3)); in MATLAB, or a compatible format in python.
The successive condition numbers should be saved in a vector of length 16 (one component for each value of n). The
successive relative errors should also be saved in a vector of length 16 (one component for each value of n).
In log-log scale, and in one graph, plot the relative errors and the condition numbers versus the respective matrix size.
To distinguish between the two lines in the plot use red-solid and ‘+’ for the relative errors and blue-dashed and ‘o’ for
the condition numbers. Use axis tight after your plot. Use labels for the axes, a legend in your plot, and a cap-
tion under your plot.
Describe how the condition numbers evolve with n, and how the relative error behaves with n. Comment on how the
relative error behaves with n. (If you need additional output to support your comments, it is fine to include it, but keep
the columns of the table aligned.)
Notes:
− If you get a warning by MATLAB, you are not necessarily doing anything wrong, but you must make a comment about
it.
− Use Euclidean norms (i.e. norm()) and condition numbers (i.e. cond()) whenever needed.
− You can use the built-in MATLAB function vander(x) to create Vandermonde matrices corresponding to points
saved in the vector x. Otherwise, use your own code, but without nested for loops.
− Use the built-in MATLAB function ones(n, 1) to create a vector of 1’s and length n.
− Estimate the relative error in a computed solution z of a linear system by
||y − z||
||z|| , where y is the exact solution.
− Use the ‘\’ division operator to solve linear systems. (This performs GE with partial pivoting.)
4.
(a) [5 points] Show that the determinant of a lower (upper) triangular matrix is the product of its diagonal entries.
(b) [10 points] Let I be the identity n × n matrix and u, v be n × 1 vectors. Show that det(I + uvT ) = (1 + vT u).
(c) [10 points] Let A be a non-singular n × n matrix and u, v be n × 1 vectors. Show that
det(A + uvT ) = det(A)(1 + vT A−1u).
Note: You can use properties of matrices and determinants mentioned in the notes without proof. Any other statement must
be shown.
CSC336 Assignment 2 C. Christara