I have the below 11x11 matrix (it is stored in P_sym.mat file attached). I get different eigen values from eig depenind on how I call it. If it computes eigen vectors it returns different eigen values than if I call eig with just eigen values specified as outputs.
For the following code, where i = 4
[v, d] = eig(P_sym,'vector');
p_sym_ispostitive_definate(i) = issymmetric(P_sym) && all(d > 0.0);
if(min(d) > 0 && min(dxx) < 0)
save('P_sym.mat','P_sym');
fprintf(1,'P_sym : %15.8e %15.8e %15.8e %15.8e %15.8e %15.8e %15.8e %15.8e %15.8e %15.8e %15.8e\n',squeeze(P_sym));
p_sym_ispostitive_definateXX = issymmetric(P_sym) && all(dxx > 0.0);
fprintf(1,[' P_sym(%d) SPD %d, symmetric %d, min_eig %15.8e, eig: ' repmat(' %15.8e',1,length(dxx)) '\n'],i,p_sym_ispostitive_definateXX, issymmetric(P_sym), min(dxx), dxx);
I get the folllowing results:
P_sym(1) SPD 1, symmetric 1, min_eig 8.90819724e-23, eig: 8.90819724e-23 8.01292127e-16 7.71071265e-12 1.83508980e-11 2.71554045e-09 3.24460252e-09 4.31101082e-03 4.04842334e-02 2.91492831e-01 1.00000000e+00 9.47720644e+00
P_sym : 2.86443726e-01 1.25605442e-01 -3.05677616e-02 3.17320309e-05 -1.41410366e-07 1.37827270e-05 0.00000000e+00 0.00000000e+00 -1.93544065e-02 -4.36768322e-07 -3.54926546e-12
P_sym : 1.25605442e-01 7.12565604e+00 -4.08080640e+00 4.76436787e-04 8.15871206e-04 -2.98861979e-04 0.00000000e+00 0.00000000e+00 -7.64780930e-02 -5.97081660e-07 -2.54538005e-12
P_sym : -3.05677616e-02 -4.08080640e+00 2.38619512e+00 -2.69887758e-04 -4.67183802e-04 1.83109375e-04 0.00000000e+00 0.00000000e+00 2.29324963e-02 -4.59895084e-07 -6.02605228e-12
P_sym : 3.17320309e-05 4.76436787e-04 -2.69887758e-04 3.61675592e-08 5.22270400e-08 -1.98733607e-08 0.00000000e+00 0.00000000e+00 -8.24258261e-06 -2.22346600e-10 -1.93099984e-15
P_sym : -1.41410366e-07 8.15871206e-04 -4.67183802e-04 5.22270400e-08 9.67373610e-08 -3.56665330e-08 0.00000000e+00 0.00000000e+00 -8.10157851e-06 -2.75926708e-11 -5.27412767e-17
P_sym : 1.37827270e-05 -2.98861979e-04 1.83109375e-04 -1.98733607e-08 -3.56665330e-08 1.78452469e-08 0.00000000e+00 0.00000000e+00 -6.41479546e-07 -6.32077553e-11 -5.51581323e-16
P_sym : 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
P_sym : 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.00000000e-18 0.00000000e+00 0.00000000e+00 0.00000000e+00
P_sym : -1.93544065e-02 -7.64780930e-02 2.29324963e-02 -8.24258261e-06 -8.10157851e-06 -6.41479546e-07 0.00000000e+00 0.00000000e+00 1.51994891e-02 6.47038249e-07 6.14697206e-12
P_sym : -4.36768322e-07 -5.97081660e-07 -4.59895084e-07 -2.22346600e-10 -2.75926708e-11 -6.32077553e-11 0.00000000e+00 0.00000000e+00 6.47038249e-07 4.01852424e-11 4.26210532e-16
P_sym : -3.54926546e-12 -2.54538005e-12 -6.02605228e-12 -1.93099984e-15 -5.27412767e-17 -5.51581323e-16 0.00000000e+00 0.00000000e+00 6.14697206e-12 4.26210532e-16 4.76317051e-21
P_sym(1) SPD 0, symmetric 1, min_eig -3.56878675e-17, eig: -3.56878675e-17 8.91986312e-23 7.71020397e-12 1.83488208e-11 2.71554106e-09 3.24460241e-09 4.31101082e-03 4.04842334e-02 2.91492831e-01 1.00000000e+00 9.47720644e+00
This is rather perplexing, because the minimum eigen value in the first call is positive, whereas in the 2nd call it is negative. This defines whether the matrix is positive definate or not. The difference that causes the output change is not the "vector" output option for eig, but rather whether eigen vectors are requested in the return.
Why the differing values? Which eig can be used with assurance to determine SPD (symmetric positive definate) matrices??
P_sym : 3.91971950e-01 -1.84707196e-02 9.64010847e-02 1.49471956e-05 -2.95043186e-05 8.41762906e-06 0.00000000e+00 0.00000000e+00 -2.63518244e-02 -8.89506787e-07 -7.63950369e-12
P_sym : -1.84707196e-02 1.10109548e+01 -5.54536247e+00 7.12947029e-04 5.49185331e-04 9.97089694e-06 0.00000000e+00 0.00000000e+00 -1.00683513e-01 -8.04754882e-07 -3.84179497e-12
P_sym : 9.64010847e-02 -5.54536247e+00 2.97740884e+00 -3.66348740e-04 -2.70925828e-04 2.66675852e-05 0.00000000e+00 0.00000000e+00 1.37117248e-02 -7.52066065e-07 -8.08110708e-12
P_sym : 1.49471956e-05 7.12947029e-04 -3.66348740e-04 4.89069796e-08 3.30828980e-08 -1.44659120e-09 0.00000000e+00 0.00000000e+00 -8.18935868e-06 -1.82559412e-10 -1.48511352e-15
P_sym : -2.95043186e-05 5.49185331e-04 -2.70925828e-04 3.30828980e-08 3.19074916e-08 1.18059503e-09 0.00000000e+00 0.00000000e+00 -4.85944277e-06 -1.22536049e-11 -4.65286216e-17
P_sym : 8.41762906e-06 9.97089694e-06 2.66675852e-05 -1.44659120e-09 1.18059503e-09 6.54728043e-09 0.00000000e+00 0.00000000e+00 -4.94291834e-06 -1.19356169e-10 -9.10766108e-16
P_sym : 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
P_sym : 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.00000000e-18 0.00000000e+00 0.00000000e+00 0.00000000e+00
P_sym : -2.63518244e-02 -1.00683513e-01 1.37117248e-02 -8.18935868e-06 -4.85944277e-06 -4.94291834e-06 0.00000000e+00 0.00000000e+00 1.90931002e-02 7.98240784e-07 7.33246401e-12
P_sym : -8.89506787e-07 -8.04754882e-07 -7.52066065e-07 -1.82559412e-10 -1.22536049e-11 -1.19356169e-10 0.00000000e+00 0.00000000e+00 7.98240784e-07 4.49272102e-11 4.51931653e-16
P_sym : -7.63950369e-12 -3.84179497e-12 -8.08110708e-12 -1.48511352e-15 -4.65286216e-17 -9.10766108e-16 0.00000000e+00 0.00000000e+00 7.33246401e-12 4.51931653e-16 4.76317051e-21