## Inconclusive results using eig in subspace iteration

### Maryam (view profile)

on 17 Apr 2019
I am trying to use "eig" command in a subspace iteration code, in which matrices A and B will be updated in each iteration in order to find the first smallest eigen values of a big problem (basically, the subspace runs through specific matrices derived from original big scale matrices). My problem is that when I use the command "eig" the code will not converge to the right solution, however, using another code for calculating eigen pairs, I am able to reach to the right result! So, I want to make sure I am not making any mistakes using "eig" in this matter.The following is my subspace iteration code:
while ecol > 10e-3 && max_Abs_error_norm > 10e-12
m_n=m_n+1;
B_mod = B*X_bar;
X_bar = A\B_mod;
A_R = X_bar'*A*X_bar;
B_R = X_bar'*B*X_bar;
[phi,val]=eig(A_R,B_R);
[val,phi,sweep]=eigenpair_generalized(A_R,B_R);
% sort
[val,ind] = sort(diag(val));
phi = phi(:, ind);
X = X_bar*phi;
for i=1:(L)
Abs_error_norm(i) = norm(A*X(:,i)-val(i)*B*X(:,i));
end
max_Abs_error_norm = max(Abs_error_norm);
X_bar = X;
if m_n~=1
for i=1:L
ecol_1(i) = norm(val(i) - val_store(i));
ecol = norm(ecol_1);
end
val_store = val;
else
end
val_store = val;
end
For example the following A_R and B_R are the starting matrices in the line 5 and 6 of the code:
A_R:
3.76356212339912e-07 -2.09083477345828e-08 6.09796273121035e-08 1.16125096563533e-10 8.54792315774798e-10 -1.78957565354304e-10 3.64588901245169e-07 -2.12575801834609e-08 2.95778384545593e-08 1.04548852037412e-10 7.54337443978326e-10 1.47918428730144e-10 3.58166253583762e-07 -1.50411486294677e-08 2.27508077139848e-09 5.08998266385549e-11 7.35592497477014e-10 1.64378433262496e-10 3.54560674790984e-07 -1.31215746002643e-08
-2.09083477342730e-08 6.72245957087280e-07 -2.18639634962637e-08 -1.71926525612297e-09 -1.27383673022489e-10 -7.11372187762411e-10 -1.88899100170015e-08 6.31741631656896e-07 -2.12006678567957e-08 -1.63021194866289e-09 -1.09372872303371e-10 -1.23421660245203e-09 -1.49898389986645e-08 5.83558489864854e-07 -2.21565565712593e-08 -1.46036349767698e-09 -6.55275941132095e-11 -1.30683725608677e-09 -1.10191105552099e-08 5.40004460879015e-07
6.09796273121098e-08 -2.18639634961972e-08 4.71171643216891e-08 1.04797054454652e-10 1.86095906819136e-10 8.01260288650236e-12 6.06016240826248e-08 -2.11963598721298e-08 4.00551836787072e-08 8.36220534690659e-11 1.70245409704536e-10 2.25668528665953e-11 6.02164452093673e-08 -2.04605143113643e-08 3.43646163430180e-08 6.78878595546358e-11 1.56927587198837e-10 1.50923000171879e-11 5.99424102846985e-08 -2.03680063346499e-08
1.16125096563414e-10 -1.71926525612101e-09 1.04797054454702e-10 1.52863228782801e-09 7.61730319665823e-11 2.90892666982479e-12 7.98277666688785e-11 -1.55127298735140e-09 5.46305600339577e-11 7.79819357940273e-10 6.11649135937128e-11 5.00382604780811e-12 5.54540465282430e-11 -1.37209673833278e-09 6.33565161940306e-11 4.34701276279994e-10 2.75780794356816e-11 4.42260486804309e-12 3.69431658456605e-11 -1.24087539226780e-09
8.54792315774812e-10 -1.27383673022310e-10 1.86095906819186e-10 7.61730319665799e-11 5.41326468653499e-10 -6.90952287312927e-13 7.82924904359684e-10 -1.19603500840236e-10 4.30335020913748e-11 6.48006877696352e-11 -1.30723786035514e-10 1.08160932502498e-12 7.47280621190149e-10 -7.09653697897241e-11 4.30795196092820e-12 2.79904115196465e-11 3.93472545836092e-11 1.47324908741991e-12 7.33942614057930e-10 -2.71725494428705e-11
-1.78957565354260e-10 -7.11372187763432e-10 8.01260288654824e-12 2.90892666982850e-12 -6.90952287312627e-13 1.92721989506897e-10 -3.63546650140569e-10 3.74107762169332e-09 1.46997960535703e-12 -6.24910441187741e-11 -3.69513695294017e-12 4.12819006950702e-11 -2.93839904430602e-10 3.65221524784282e-09 -1.44420664706842e-11 -5.52483429664814e-11 -3.37784740323818e-12 -3.64319630028251e-11 -1.19667813242863e-10 1.78034756805592e-09
3.64588901245383e-07 -1.88899100173116e-08 6.06016240826821e-08 7.98277666689620e-11 7.82924904360137e-10 -3.63546650140585e-10 3.68457091745830e-07 -2.66935246645527e-08 3.01059891783646e-08 1.99885274915102e-10 7.67339896837451e-10 -2.81002492354834e-13 3.60658741504259e-07 -2.17263381445007e-08 2.42466362641430e-09 1.59025755093987e-10 7.49949375418138e-10 2.24074497973733e-10 3.56302082753645e-07 -1.62123724739677e-08
-2.12575801833362e-08 6.31741631655756e-07 -2.11963598721385e-08 -1.55127298735091e-09 -1.19603500840958e-10 3.74107762169481e-09 -2.66935246644314e-08 7.60571341160095e-07 -2.14588169242276e-08 -3.86341835071549e-09 -2.30122027434400e-10 1.49679463458960e-09 -2.27314217189395e-08 7.35340682198992e-07 -2.33641804935095e-08 -3.71231499081196e-09 -1.95793125778234e-10 -2.35950158696086e-09 -1.27171200877616e-08 6.23793130032960e-07
2.95778384546184e-08 -2.12006678566718e-08 4.00551836787374e-08 5.46305600338521e-11 4.30335020914587e-11 1.46997960531807e-12 3.01059891783790e-08 -2.14588169241900e-08 3.81776796219074e-08 5.18761021398917e-11 7.78938391626599e-11 -1.48784260116095e-11 3.07221849868984e-08 -2.21488913895600e-08 3.46435071832503e-08 5.42872965395875e-11 9.78734212714599e-11 -2.34743082420234e-11 3.08820328445443e-08 -2.30743445571125e-08
1.04548852037193e-10 -1.63021194866473e-09 8.36220534690290e-11 7.79819357940281e-10 6.48006877696373e-11 -6.24910441187760e-11 1.99885274914897e-10 -3.86341835071973e-09 5.18761021399497e-11 2.88177278801690e-09 1.73527560308934e-10 -2.95791573566135e-11 1.63606363716668e-10 -3.68578964581812e-09 6.70215594167807e-11 1.22058356343448e-09 8.92850271129233e-11 3.15485751136804e-11 2.84994769414440e-11 -2.11221283724199e-09
7.54337443978436e-10 -1.09372872303155e-10 1.70245409704461e-10 6.11649135937103e-11 -1.30723786035513e-10 -3.69513695294040e-12 7.67339896837094e-10 -2.30122027433637e-10 7.78938391624351e-11 1.73527560308932e-10 3.46432736834289e-10 -1.12406376222186e-12 7.50317584899563e-10 -1.87522593302975e-10 -1.80471539474028e-11 8.88175404651439e-11 -7.93438089784584e-11 2.87711136829571e-12 7.27773344056736e-10 -6.42461727021362e-11
1.47918428730006e-10 -1.23421660245135e-09 2.25668528666373e-11 5.00382604780913e-12 1.08160932502493e-12 4.12819006950679e-11 -2.81002492560337e-13 1.49679463458976e-09 -1.48784260115529e-11 -2.95791573566149e-11 -1.12406376222197e-12 1.09083345682025e-10 -9.64214208670492e-11 3.24114993582077e-09 -4.18518424101429e-11 -4.65083941209266e-11 -2.50797392263328e-12 -3.00226119639900e-12 1.83091308587572e-13 2.15157500137760e-09
3.58166253583768e-07 -1.49898389985222e-08 6.02164452093692e-08 5.54540465271538e-11 7.47280621190082e-10 -2.93839904430733e-10 3.60658741504051e-07 -2.27314217186113e-08 3.07221849868459e-08 1.63606363715694e-10 7.50317584899407e-10 -9.64214208669632e-11 3.65950838935299e-07 -2.22602622183909e-08 3.16641956823605e-09 1.81228263568791e-10 7.59258684937204e-10 1.05612398949466e-10 3.60166698741223e-07 -1.85495439881304e-08
-1.50411486292207e-08 5.83558489864239e-07 -2.04605143112627e-08 -1.37209673833316e-09 -7.09653697900512e-11 3.65221524784373e-09 -2.17263381442592e-08 7.35340682199476e-07 -2.21488913895049e-08 -3.68578964581487e-09 -1.87522593303351e-10 3.24114993582009e-09 -2.22602622185929e-08 7.91568787872354e-07 -2.49809473107789e-08 -4.40252789724911e-09 -2.19862365855565e-10 -8.03338283539586e-10 -1.28100070022144e-08 6.89221184971151e-07
2.27508077138558e-09 -2.21565565711633e-08 3.43646163429808e-08 6.33565161940717e-11 4.30795196082818e-12 -1.44420664707220e-11 2.42466362637398e-09 -2.33641804935264e-08 3.46435071831961e-08 6.70215594168454e-11 -1.80471539473478e-11 -4.18518424102022e-11 3.16641956821771e-09 -2.49809473108718e-08 3.54040276314082e-08 7.01764235234317e-11 1.08584807703397e-11 -4.41705306949284e-11 3.86500134382531e-09 -2.62755292014477e-08
5.08998266378311e-11 -1.46036349767480e-09 6.78878595545626e-11 4.34701276279992e-10 2.79904115196472e-11 -5.52483429664834e-11 1.59025755093255e-10 -3.71231499081219e-09 5.42872965396344e-11 1.22058356343447e-09 8.88175404651449e-11 -4.65083941209257e-11 1.81228263569274e-10 -4.40252789724833e-09 7.01764235233811e-11 2.82955458725984e-09 1.72557303180453e-10 1.82704202202530e-11 2.16827623046118e-11 -2.60335537517938e-09
7.35592497477138e-10 -6.55275941130801e-11 1.56927587198836e-10 2.75780794356793e-11 3.93472545836096e-11 -3.37784740323805e-12 7.49949375417793e-10 -1.95793125777536e-10 9.78734212713035e-11 8.92850271129213e-11 -7.93438089784584e-11 -2.50797392263277e-12 7.59258684937375e-10 -2.19862365855229e-10 1.08584807703583e-11 1.72557303180452e-10 3.17171312398712e-10 1.72011526210266e-12 7.37098952218238e-10 -9.04254755268285e-11
1.64378433262459e-10 -1.30683725608595e-09 1.50923000172512e-11 4.42260486804383e-12 1.47324908742001e-12 -3.64319630028272e-11 2.24074497973588e-10 -2.35950158696059e-09 -2.34743082419399e-11 3.15485751136785e-11 2.87711136829583e-12 -3.00226119639894e-12 1.05612398949461e-10 -8.03338283538727e-10 -4.41705306948583e-11 1.82704202202513e-11 1.72011526210234e-12 9.85304668395987e-11 -4.42277941760844e-11 1.16333442362982e-09
3.54560674790922e-07 -1.10191105554018e-08 5.99424102846489e-08 3.69431658454348e-11 7.33942614057819e-10 -1.19667813242919e-10 3.56302082753370e-07 -1.27171200877633e-08 3.08820328444444e-08 2.84994769413042e-11 7.27773344056533e-10 1.83091308727651e-13 3.60166698741156e-07 -1.28100070023421e-08 3.86500134380002e-09 2.16827623049751e-11 7.37098952218022e-10 -4.42277941760294e-11 3.68315665272456e-07 -1.70339354406870e-08
-1.31215746003486e-08 5.40004460878439e-07 -2.03680063346909e-08 -1.24087539226858e-09 -2.71725494440965e-11 1.78034756805778e-09 -1.62123724740641e-08 6.23793130033510e-07 -2.30743445571644e-08 -2.11221283723928e-09 -6.42461727033928e-11 2.15157500137820e-09 -1.85495439886669e-08 6.89221184971287e-07 -2.62755292014313e-08 -2.60335537518070e-09 -9.04254755280503e-11 1.16333442363027e-09 -1.70339354408992e-08 6.94213867084590e-07
B_R:
1.03175870178633e-11 -8.79189553052589e-13 1.59080116742470e-12 2.41621405638158e-15 1.86501722980406e-14 1.75366390056084e-15 1.03015258408236e-11 -8.46789116527407e-13 8.68678582458295e-13 -2.24360437230112e-15 1.78152395185980e-14 3.83377709016405e-17 1.02911879350126e-11 -8.68517875894631e-13 1.98882940613445e-13 -7.66868893630347e-16 1.80768784756857e-14 -1.15335552306608e-15 1.02832608622751e-11 -9.35051442530130e-13
-8.79189553052589e-13 3.07933014329677e-11 -5.33779632938920e-13 -6.73116062869727e-14 -2.11096786035912e-15 5.06288499645210e-15 -8.77534823669352e-13 3.10119430876808e-11 -6.33107580772930e-13 -5.72750476585272e-14 -1.36275575411084e-15 4.26119772787913e-15 -8.58980396148295e-13 3.10660190503380e-11 -7.32115747563086e-13 -5.66762567173829e-14 -1.02637635181665e-15 -1.73706942711061e-15 -8.31427403738532e-13 3.08967475380148e-11
1.59080116742470e-12 -5.33779632938920e-13 6.80081216548998e-13 1.67237428831680e-15 3.18450275041731e-15 -2.25342161992527e-16 1.58968123534381e-12 -5.54043072699924e-13 5.61778214330174e-13 -2.13701339994040e-15 2.80097939571704e-15 -6.64976529070739e-16 1.59020011907950e-12 -5.78759312660347e-13 4.50862065740340e-13 -1.75201577457165e-15 2.89626592960965e-15 -6.22844231739234e-16 1.59045868464300e-12 -5.98693289728591e-13
2.41621405638158e-15 -6.73116062869727e-14 1.67237428831680e-15 1.69839597204020e-16 8.06257956537145e-18 -1.79450462577336e-17 2.42558213172486e-15 -6.80793259088731e-14 1.86076272565477e-15 3.37129879193649e-17 -2.83829117045900e-18 -1.59839338809655e-17 2.39455453891153e-15 -6.83940868161955e-14 2.05027481277136e-15 6.47752416750080e-17 -9.79577591755958e-19 -1.47964767262689e-19 2.33959226469519e-15 -6.81324290509276e-14
1.86501722980406e-14 -2.11096786035912e-15 3.18450275041731e-15 8.06257956537145e-18 3.77545202946311e-17 2.71620310354043e-18 1.86177206991257e-14 -2.07488756141497e-15 1.77837650125942e-15 -1.70115916793987e-17 3.34622101556667e-17 -3.75185636758635e-19 1.85960462667111e-14 -2.12139614900033e-15 4.75060130985000e-16 -7.06698644505299e-18 3.48892199263426e-17 -2.05724402977358e-18 1.85791363911028e-14 -2.23902549610310e-15
1.75366390056084e-15 5.06288499645210e-15 -2.25342161992527e-16 -1.79450462577336e-17 2.71620310354043e-18 6.91028308356056e-17 1.59537346777557e-15 7.97160556584950e-15 -3.93072902749984e-16 -2.52322583272137e-17 2.71899624296322e-18 6.70190257914095e-17 1.48508091324466e-15 9.86912906944127e-15 -5.62193762595592e-16 -2.63098066039009e-17 2.81973530627402e-18 3.34120902897812e-17 1.43579582353904e-15 1.05007821174212e-14
1.03015258408236e-11 -8.77534823669352e-13 1.58968123534381e-12 2.42558213172486e-15 1.86177206991257e-14 1.59537346777557e-15 1.02861749361966e-11 -8.51318400091087e-13 8.68853093671712e-13 -2.22323221334048e-15 1.77849304648435e-14 -9.91568736846405e-17 1.02762726382151e-11 -8.76896387641732e-13 2.00214055060591e-13 -7.41998084289500e-16 1.80476465723590e-14 -1.22102399755875e-15 1.02685833471280e-11 -9.44694398689834e-13
-8.46789116527407e-13 3.10119430876808e-11 -5.54043072699924e-13 -6.80793259088731e-14 -2.07488756141497e-15 7.97160556584950e-15 -8.51318400091087e-13 3.13592439957615e-11 -6.57539577667682e-13 -5.83505610933747e-14 -1.31924406837513e-15 7.39257482256016e-15 -8.38092019200837e-13 3.15085210860475e-11 -7.61072518925006e-13 -5.76376349842803e-14 -9.67458812822737e-16 1.42976476519421e-16 -8.13775885142815e-13 3.13822730405345e-11
8.68678582458295e-13 -6.33107580772930e-13 5.61778214330174e-13 1.86076272565477e-15 1.77837650125942e-15 -3.93072902749984e-16 8.68853093671712e-13 -6.57539577667682e-13 4.99077514150276e-13 -1.61439718383837e-15 1.45220827521035e-15 -7.11000184858285e-16 8.70145181808812e-13 -6.81812285772681e-13 4.39724459235748e-13 -1.46665759087932e-15 1.51992860891018e-15 -5.52918207747300e-16 8.70907191555085e-13 -6.96674003683227e-13
-2.24360437230112e-15 -5.72750476585272e-14 -2.13701339994040e-15 3.37129879193649e-17 -1.70115916793987e-17 -2.52322583272137e-17 -2.22323221334048e-15 -5.83505610933747e-14 -1.61439718383837e-15 1.10530188669580e-15 6.32479434004739e-17 -2.41415125622093e-17 -2.24689611084515e-15 -5.88891747936772e-14 -1.07498124204802e-15 3.00095349665415e-16 4.94238469009342e-18 -1.43192043140587e-18 -2.31286233836143e-15 -5.84614027679227e-14
1.78152395185980e-14 -1.36275575411084e-15 2.80097939571704e-15 -2.83829117045900e-18 3.34622101556667e-17 2.71899624296322e-18 1.77849304648435e-14 -1.31924406837513e-15 1.45220827521035e-15 6.32479434004739e-17 3.81632876282334e-17 -1.85434863020401e-19 1.77644255608822e-14 -1.35845894083283e-15 2.04502009867279e-16 1.38818444560346e-17 3.45811786730111e-17 -1.70660706602461e-18 1.77477890142585e-14 -1.45388301885047e-15
3.83377709016405e-17 4.26119772787913e-15 -6.64976529070739e-16 -1.59839338809655e-17 -3.75185636758635e-19 6.70190257914095e-17 -9.91568736846405e-17 7.39257482256016e-15 -7.11000184858285e-16 -2.41415125622093e-17 -1.85434863020401e-19 8.15233240283562e-17 -2.52753761553961e-16 1.00979525754716e-14 -7.69147897817628e-16 -1.50460117328612e-17 5.98409251705107e-19 6.02207045130483e-17 -3.76060483047238e-16 1.17121915331849e-14
1.02911879350126e-11 -8.58980396148295e-13 1.59020011907950e-12 2.39455453891153e-15 1.85960462667111e-14 1.48508091324466e-15 1.02762726382151e-11 -8.38092019200837e-13 8.70145181808812e-13 -2.24689611084515e-15 1.77644255608822e-14 -2.52753761553961e-16 1.02670258030600e-11 -8.69589101439028e-13 2.02183527757951e-13 -7.98411611363664e-16 1.80260447185248e-14 -1.37895062488491e-15 1.02599451558608e-11 -9.42484141614535e-13
-8.68517875894631e-13 3.10660190503380e-11 -5.78759312660347e-13 -6.83940868161955e-14 -2.12139614900033e-15 9.86912906944127e-15 -8.76896387641732e-13 3.15085210860475e-11 -6.81812285772681e-13 -5.88891747936772e-14 -1.35845894083283e-15 1.00979525754716e-14 -8.69589101439028e-13 3.17579653822493e-11 -7.85334507737281e-13 -5.76977808352337e-14 -9.70406188412256e-16 2.68102265882312e-15 -8.51387724311434e-13 3.17102316907056e-11
1.98882940613445e-13 -7.32115747563086e-13 4.50862065740340e-13 2.05027481277136e-15 4.75060130985000e-16 -5.62193762595592e-16 2.00214055060591e-13 -7.61072518925006e-13 4.39724459235748e-13 -1.07498124204802e-15 2.04502009867279e-16 -7.69147897817628e-16 2.02183527757951e-13 -7.85334507737281e-13 4.28246671817594e-13 -1.15597577004508e-15 2.44825637095337e-16 -4.93380515707506e-16 2.03383332661456e-13 -7.95513643765350e-13
-7.66868893630347e-16 -5.66762567173829e-14 -1.75201577457165e-15 6.47752416750080e-17 -7.06698644505298e-18 -2.63098066039009e-17 -7.41998084289500e-16 -5.76376349842803e-14 -1.46665759087932e-15 3.00095349665415e-16 1.38818444560346e-17 -1.50460117328612e-17 -7.98411611363664e-16 -5.76977808352337e-14 -1.15597577004508e-15 1.02641640456051e-15 6.09531483196836e-17 1.11768744317099e-17 -9.03040601292049e-16 -5.69614765479726e-14
1.80768784756857e-14 -1.02637635181665e-15 2.89626592960965e-15 -9.79577591755958e-19 3.48892199263426e-17 2.81973530627402e-18 1.80476465723590e-14 -9.67458812822737e-16 1.51992860891018e-15 4.94238469009342e-18 3.45811786730111e-17 5.98409251705107e-19 1.80260447185248e-14 -9.70406188412256e-16 2.44825637095336e-16 6.09531483196836e-17 3.87606240635733e-17 -8.27496938825935e-19 1.80073832850448e-14 -1.04676157768245e-15
-1.15335552306608e-15 -1.73706942711061e-15 -6.22844231739234e-16 -1.47964767262689e-19 -2.05724402977358e-18 3.34120902897812e-17 -1.22102399755875e-15 1.42976476519421e-16 -5.52918207747300e-16 -1.43192043140587e-18 -1.70660706602461e-18 6.02207045130483e-17 -1.37895062488491e-15 2.68102265882312e-15 -4.93380515707506e-16 1.11768744317099e-17 -8.27496938825935e-19 7.30906664166234e-17 -1.58010253385405e-15 5.22330664693345e-15
1.02832608622751e-11 -8.31427403738532e-13 1.59045868464300e-12 2.33959226469519e-15 1.85791363911028e-14 1.43579582353904e-15 1.02685833471280e-11 -8.13775885142815e-13 8.70907191555085e-13 -2.31286233836143e-15 1.77477890142585e-14 -3.76060483047238e-16 1.02599451558608e-11 -8.51387724311434e-13 2.03383332661456e-13 -9.03040601292049e-16 1.80073832850448e-14 -1.58010253385405e-15 1.02538038134095e-11 -9.31957326233159e-13
-9.35051442530130e-13 3.08967475380148e-11 -5.98693289728591e-13 -6.81324290509276e-14 -2.23902549610310e-15 1.05007821174212e-14 -9.44694398689834e-13 3.13822730405345e-11 -6.96674003683227e-13 -5.84614027679227e-14 -1.45388301885047e-15 1.17121915331849e-14 -9.42484141614534e-13 3.17102316907056e-11 -7.95513643765350e-13 -5.69614765479726e-14 -1.04676157768245e-15 5.22330664693345e-15 -9.31957326233160e-13 3.17598704040834e-11