Hi All,<br><br>Can anyone tell me why the singular value decomposition (svd_lapack) below yields different eigenvalues than the eigenanalysis (eofunc, eofunc_ts), while both output the exact same EOFs and PCs? Can't see what I'm doing wrong. Code and output are below.<br>
<br>Thanks!<br>Kerrie<br><br><br>;######################################################################################<br>;### data array A=(/ntime,nspace/) ###<br>A=(/ (/-2.,1./),(/7.,-8./),(/-3.,0./),(/5.,-9./) /)<br>
A!0="time"<br>A!1="space"<br>ntime=4 ;### number of rows, time dimension 0 ###<br>nspace=2 ;### number of columns, space dimension 1 ###<br><br> Aprime = dim_rmvmean_n(A,0)<br> ;### singular value decomposition of Aprime ### <br>
;### Aprime=(u)(s)(vtranspose)-----> (4x2)=(4x2)(2x2)(2x2) ###<br> u = new ( (/ntime,nspace/) , float ) ;### columns of u are PC eigenvectors ###<br> vtranspose = new ( (/nspace,nspace/) , float ) ;### rows of vtranspose are EOF eigenvectors ###<br>
s = svd_lapack (Aprime, "S" , "S", 0, vtranspose, u) ;### s^2=eigenvalues<br> ;### s is returned with only the non-zero (diagonal) values<br><br> print("for SVD")<br> print("U:")<br>
write_matrix (u, "2f10.4", False)<br> print("V:")<br> write_matrix (vtranspose, "2f10.4", False)<br> print("lambda:")<br> print(s^2)<br><br><br> At=transpose(A) ;### make time the rightmost dimension ###<br>
eof=eofunc(At,2,False) ;### rows of eof are EOFs ###<br> eoftranspose=transpose(eof)<br> pc=eofunc_ts_Wrap(At,eof,False) ;### rows of pc are PCs ###<br> pctranspose=transpose(pc) ;### for similarity to SVD matrices, now columns of pc are PCs ###<br>
pc_colsum=dim_sum_n(pctranspose^2,0) ;### square each component and sum the columns ###<br> pctranspose(:,0)=pctranspose(:,0)/sqrt(pc_colsum(0)) ;### normalize PC1<br> pctranspose(:,1)=pctranspose(:,1)/sqrt(pc_colsum(1)) ;### normalize PC2<br>
<br> print("for eofunc")<br> print("U:")<br> write_matrix (pctranspose, "2f10.4", False)<br> print("V:")<br> write_matrix (eof, "2f10.4", False)<br>
print("lambda:")<br> print(eof@eval)<br>;######################################################################################<br><br><br>OUPUT IS:<br><br><span style="color: rgb(51, 51, 255);">(0) for SVD</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">(0) U:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);"> </span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);"> 0.5010 0.4050</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);"> -0.5261 0.5745</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);"> 0.4983 -0.3748</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);"> -0.4732 -0.6046</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);"> </span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">(0) V:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);"> </span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);"> -0.6898 0.7240</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);"> 0.7240 0.6898</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);"> </span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">(0) lambda:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">(0) 153.4626</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">(1) 3.287447</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">(0) </span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">(0) </span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">(0) for eofunc</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">(0) U:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);"> </span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);"> 0.5010 0.4050</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);"> -0.5261 0.5745</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);"> 0.4983 -0.3748</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);"> -0.4732 -0.6046</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);"> </span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">(0) V:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);"> </span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);"> -0.6898 0.7240</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);"> 0.7240 0.6898</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);"> </span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">(0) lambda:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">(0) 51.15419</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">(1) 1.095816</span><br>
<br><br><br><br>