代写CSCI 421 Numerical Computing, Spring 2025 Homework Assignment 7代做Matlab编程

CSCI 421

Numerical Computing, Spring 2025

Homework Assignment 7

1.  (20 points) Implement the  (normalized) power method  (AG p. 289), inverse iteration (AG p. 294) and the Rayleigh quotient iteration (AG p.  295).    They  all  use  the  notation  μk   =  vk(T)Avk   for  the  Rayleigh quotient  (note  that  the  usual  Rayleigh  quotient  denominator  vk(T)vk is always one).  In inverse iteration, for efficiency you need to do the LU factorization of the matrix A - αI outside the loop and then use forward and back substitution  (using \ is fine) inside the loop.  This is not possible for the Rayleigh quotient iteration because the matrix depends on the iteration counter k.  In all cases compute and display the  eigenvalue  residual  norm   ⅡAvk  - μkvk Ⅱ  at  the  end  of  the  loop and terminate when  either the residual norm less than  10—14  or the iteration counter k reaches  100.  Also print k , μk  and the eigenvalue residual norm at the end of the loop using fprintf.

Run all 3 iterations on the tridiagonal matrix T computed from calling tridiagExample.m, with inputs N=100 and nonsym=0 .1.  Set v0  to the vector of all ones.  For inverse iteration, use α = 4.  Using semilogy, plot the residual norms of all 3 methods on the same  plot.  Explain carefully how the plot demonstrates what we discussed about the con- vergence of these 3 methods in class.  Note that the Rayleigh quotient iteration does not find the largest eigenvalue of T, unlike the other 2 methods.

2.  (20 pts) As I mentioned  in class, if we first compute the eigenvalues of a matrix A and then later we decide we want the eigenvector corre- sponding to a computed eigenvalue λ, we can do this very effectively by solving the equation  (A - λI)x = b, where b is chosen randomly. This amounts to just one  step of inverse iteration (the inverse power method) using the shift λ .  The reason it works is that λ is not exactly an eigenvalue  of A and hence  A - λI is  not  exactly  singular.   It  is very badly conditioned, so there is a lot of rounding error incurred in solving the equation, but luckily, and very surprisingly, the rounding error is almost entirely in the magnitude of the solution x, not the di- rection.  But we don’t care about the magnitude because we are going to normalize x anyway.  And the reason the resulting x is very close to an eigenvector is the same reason that the inverse power iteration converges so fast: see AG p. 293 and my notes. Verify these claims as follows:

•  choose a random square matrix with odd order, say 11 or 101, so that it must have at least one real eigenvalue

•  compute its eigenvalues with evalues = eig(A)

•  choose one of the computed real eigenvalues  for  λ  (using real or  imag)  and  solve  (A − λI)x  =  b  using  \,  where  b is  chosen randomly – note that Matlab gives you a warning about A−λI being nearly singular

•  normalize x by dividing by its 2-norm

•  check the eigenvalue-eigenvector residual  ⅡAx − λxⅡ2 :  it  should be around machine precision

•  another much more expensive way to find the eigenvector  is to compute the SVD of B = A − λI.  The eigenvector  of A corre- sponding to the eigenvalue λ is one of the left or right singular vectors of B: which one and why?

3.  (30 pts) This concerns the SVD Block Power method for approximat- ing the largest r singular values and corresponding singular vectors of an m × n matrix A, where r is less than n, usually much less:

Initialize V0  to an n × r matrix For k = 1, 2, . . .

Set U(ˆ) = AVk 1

Get reduced QR factorization U(ˆ) = QURU

Set Uk  = QU

Set V(ˆ) = AT Uk

Get reduced QR factorization V(ˆ) = QVRV

Set Vk  = QV

This is also given on p. 22-6 of my lecture notes for April 14, but it is not discussed by AG.

(a)  The  signs  of  the  diagonal  entries  of  R  in  a  QR  factorization are  arbitrary:   although  Gram-Schmidt  (which  we  are  not  us- ing) chooses them to be positive, Householder (which Matlab’s qr uses) does not.   Since we’d like them to be positive in the next part, write a short Matlab function [Q,R]=qrPosDiagR(A) which computes the reduced Q and R factors of A by calling Mat- lab’s qr(A,0) and then modifies the Q and R factors so that the diagonal entries of R are all positive (or zero, but that’s unlikely), by changing the sign of the corresponding row of R and the cor- responding column of Q, so that the equations A = QR still holds (check this!)  One way to see that this “works” is to observe that QR = QS2 R = (QS)(SR) where S is a diagonal matrix of ±1’s.

(b)  Implement the SVD Block Power method given above.

Use qrPosDiagR for both QR factorizations in the loop. It turns out that for random matrices, both the upper triangular matri- ces RU  and RV  converge to diagonal matrices,  so compute the matrix 2-norm of the strictly upper triangular parts of both RU  and RV  (either by using triu( .,1) or by subtracting off the di- agonal  entries)  and terminate  the  loop  when the  maximum  of these  two  norms  is  less  than  a  tolerance,  tol.   The  inputs  to this function should be an m × n matrix A (it should not mat- ter whether m  > n,  m =  n or  m  < n),  an  integer  r defining the number of columns in  Uk  and  Vk  that  is  usually much less than m and n, and the tolerance tol.  Before the loop,  set the initial matrix V0  to the n × r matrix whose columns are the first r columns of the n × n identity matrix, obtained by eye(n,r); you can get m and n from  size(A). This block power method can be slow, like the block power iteration for eigenvalues,  but it works pretty well when r is small.   Run it on this matrix A, setting r = 3 and setting tol to say 10—6  (you can also try other values if you like).  Now compare the diagonal entries of the final RU  and RV  to the largest r singular values of A which you can compute from Matlab’s svd. Are they good approximations to the singular values?  How do the final  Uk  and  Vk  compare with the corresponding singular vectors computed by Matlab’s svd?

(c)  It is not hard to see from the SVD notes that the r largest singular

values and the corresponding singular vectors of A, defined by

Σ(˜) = diag(σ1,... ,σr ),   U(˜) = [u1,... , ur ],   V(˜) = [v1,... , vr ],

satisfy  AV(˜) = U(˜)Σ(˜) and ATU(˜) =V(˜)Σ(˜) .  Explain why when the block

power method terminates it must be the case that

ⅡAVk— 1   UkDUⅡ ≤ tol and ⅡAT Uk VkDVⅡ ≤ tol,

where DU  and DV  are respectively the diagonals of RU  and RV , and also check to make sure that this is actually the case on the example you tested.  These small residuals help to explain why the approximations  to the singular values  and singular vectors computed by the block power method are meaningful provided the tolerance condition is satisfied.

(d)  What  is  the  operation  count  for  each  iteration  of the  loop,  in terms of r, m, n using Big O? Explain your reasoning.

4.  (30 pts) Download WallOfWindows.jpg and read it into Matlab:

A=imread(’WallOfWindows.jpg’,’jpg’)

Display it with image(A). If you type whos A you will see that A is a 3456 × 4608 × 3 three-dimensional “matrix” (or tensor) of unsigned 8-bit integers.  Split these into red, green and blue components, each a 3456 × 4608 matrix of unsigned integers, via A_red=A(:,:,1), etc, and convert these to double precision matrices using double.

(a)  Compute the reduced  (economy-sized)  SVD of each  color com- ponent matrix separately using Matlab’s svd(M,0).  Then, for each component matrix, compute its nearest rank r approxima- tion (see p. 6–7 of Notes on Eigenvalues and Singular Values), for r = 10, 20, 30 and 100.  Recombine them into the 3456 × 4608 × 3 uint8 format, and then display the resulting four pictures using image, labelling them appropriately.  How well do they approxi- mate the original picture in your opinion? This shows that SVD is a useful approach to image compression: instead of storing the whole matrix, you need only to store the part of the SVD needed to construct the rank r approximation:  how much storage does this require, in terms of m, n and r?

(b)  The problem with the method just described is that it is expensive to call svd on such a large matrix and it would take much too long for a much larger matrix.  Can you get pictures that are just as good using your block power method from the previous question, with less computational expense, again using r = 10, 20, 30 and 100? For the singular values, you could use the diagonal of either the final RU  or RV  or an average of the two, and for the singular vectors, use the final Uk  and  Vk .  You  may  find you don’t have to make the tolerance in the block power method very small to get good pictures.  How big can you make tol and still get good pictures, in your opinion, and how does the time required compare to the time required using svd?





热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图