function d = my_eig(A)
that computes all the eigenvalues (eigenvectors not required) of a
symmetric matrix A without using Matlab functions such as
eig or schur. Just do a simple implemention of
the explicit single-shift QR algorithm as given in the textbook.
Use hess to tridiagonalize the matrix first before QR.
Choose the shift to be the diagonal element to the right of the
largest lower-diagonal element at each iteration.
Run this scritp test_eig.m
to test your function. You can try on the instructor's
pcode yz_eig.p.
(b) Write a Matlab function
function [A,B] = my_pca(M,r)
to generate 2 low-rank matrices A and B so that A*B approximates
M while the storage used by A and B is equal to r*100 percent of
that used by M. We will test your function using an image M.
You should use Matlab SVD function to do this "principle component
analysis" on images.
Run this scritp test_pca.m with
different r less than 1 to test your function. You can try on the
instructor's pcode yz_pca.p.
The test image is cameraman2.jpg.
function x = mylls_qr(A,b)
It should generate the same results as the Matlab command x = A\b
without using the backslash. Use the QR factorization
with column permutation.
function x = mylls_svd(A,b)
It should generate the same results as the Matlab command x =
pinv(A)*b without using the pinv function. Use the
singular value decomposition (SVD).
function x = mylls_chol(A,b)
You should use the sparse Cholesky factorization with proper ordering
to solve the normal equations of the LLS problem.
min S(x,y,z), st. V(x,y,z) = V0, y + z = h0
max V(x,y,z), st. S(x,y,z) = S0, y + z = h0
where S is the surface area and V is the volume
of the tent which has a square base of 2x by 2x,
a height of y for the main body, and a height of
z for the pyramid top. The tent does not have a bottom.
Your matlab functions for the 2 problems should have the interfaces:[S,x,y,z,v] = mytent1(V0,h0); [V,x,y,z,v] = mytent2(S0,h0);where the lower case v is the Langrange multiplier vector. You may use finite difference approximation for the Jacobian of the Langrangian system.
Without your codes, you can run the test with the instructor's pcodes pfiles.zip.
function y = myT5(x,flag) % % Evaluate the Chebychev polynomial of degree 5, % T5(x), from 6 different formulas % % input: % x -- a column vector % flag -- indicates formula 1 to 6 % output: % y -- T5(x), same size as xThen use this test script to test your code testT5.m.
We will use this script to test your code myspline.m. In general, your code should generate a different spline than that from either pchiptx.m or splinetx.m, but it should generate the same one as that from this code.
Ax = b; A'*y = x; A*z = y;
The input is (A,b) and the output is (x,y,z).
You can implement the function anyway you want.
if exist('mychol','file')
[R,fail] = mychol(A);
else
[R,fail] = chol(A);
end
Test your code by runing the test script
test_bslash.m for a reasonably large n value
(say, n >= 2000).