This forum has been archived. All content is frozen. Please use KDE Discuss instead.

problem of matrix inversion

Tags: None
(comma "," separated)
sergeik
Registered Member
Posts
6
Karma
0

problem of matrix inversion

Thu Aug 30, 2012 1:51 pm
Hi,
I try to invert a matrix
typedef Eigen::Matrix<double,Dynamic,Dynamic> Matrix_eigen;
Matrix_eigen G1(3,3);

G1(0,0)=2.6446028165785937e-011;
G1(0,1)=-1.3223014082892972e-011;G1(0,2)=-1.3223014082892954e-011;
G1(1,0)=-1.3223014082892965e-011;G1(1,1)=2.6446445665067862e-011;G1(1,2)=-1.3223431582174882e-011;
G1(2,0)=-1.3223014082892968e-011;G1(2,1)=-1.3223431582174882e-011;G1(2,2)=2.6446445665067856e-011;

if I use .inverse (PartialPiv)the result will be
3.4387223313482796e+025 3.4387223313482762e+025 3.4387223313482758e+025
3.4387223313482771e+025 3.4387223313482784e+025 3.4387223313482753e+025
3.4387223313482775e+025 3.4387223313482766e+025 3.4387223313482784e+025

if I use .inverse (FullPiv) the result will be
3.0948500982134509e+025 3.0948500982134479e+025 3.0948500982134466e+025
3.0948500982134483e+025 3.0948500982134504e+025 3.0948500982134466e+025
3.0948500982134487e+025 3.0948500982134479e+025 3.0948500982134491e+025

if I use Mathcad 14 the result will be
3.1250000000000830366e25 3.1250000000000802006e25 3.1250000000000792553e25
3.1250000000000802006e25 3.1250000000000824063e25 3.1250000000000789402e25
3.1250000000000809096e25 3.1250000000000805945e25 3.12500000000008217e25



if I use .inverse.inverse (FullPiv) the result will be
2.7391840429866995е-011 -1.3695920314933494e-011 -1.3695920314933485e-011;
-1.1413266845777912e-011 2.5109187060711425e-011 -1.369592031493506e-011;
-1.5978573584089084e-011 -1.1413266845777921e-011 2.7391840429867015e-011;

im Mathcad the result will be (after two inverses)
2.644593129347101581e-11 -1.3222965646735497905e-11
-1.3222965646735506905e-11
-1.3222965646735249775e-11 2.6446455847804311654e-11
-1.3223490201069046878e-11
-1.3222965646735762035e-11 -1.3223490201068805749e-11 2.6446455847804573784e-11

it is obvious that a large number of condition, but why mathcad precisely?

P.S. cond=~e+16
manuels
Registered Member
Posts
47
Karma
0

Re: problem of matrix inversion

Thu Aug 30, 2012 2:01 pm
maybe Mathcat checks for double inversion and neglegts it.

Have you tried to calculate (G1*G1.inverse()) in Eigen and Mathcat?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: problem of matrix inversion

Thu Aug 30, 2012 3:11 pm
You not compute the inverse explicitly but instead store a factorization and use solve instead of *:

G1.inverse() * A

becomes:

G1.fullPivLu().solve(A)

or

FullPivLu<Matrix_matrix> lu(G1);
lu.solve(A);

This way you preserve full accuracy.

Now regarding the difference with Mathcad, one should check whether Mathcad is using double or long double.
sergeik
Registered Member
Posts
6
Karma
0

Re: problem of matrix inversion  Topic is solved

Thu Aug 30, 2012 7:30 pm
manuels wrote:maybe Mathcat checks for double inversion and neglegts it.

Have you tried to calculate (G1*G1.inverse()) in Eigen and Mathcat?

eigen:
0.9375 0.0625 -0.25
-0.125 0.9375 0
-0.0625 -0.125 0.875

mathcad
1*10^0 0*10^0 0*10^0
125*10^-3 937.5*10^-3 62.5*10^-3
-125*10^-3 0*10^0 1*10^0

Last edited by sergeik on Thu Aug 30, 2012 7:50 pm, edited 2 times in total.
sergeik
Registered Member
Posts
6
Karma
0

Re: problem of matrix inversion

Thu Aug 30, 2012 7:42 pm
ggael wrote:You not compute the inverse explicitly but instead store a factorization and use solve instead of *:
G1.inverse() * A
becomes:
G1.fullPivLu().solve(A)
or
FullPivLu<Matrix_matrix> lu(G1);
lu.solve(A);
This way you preserve full accuracy.
Now regarding the difference with Mathcad, one should check whether Mathcad is using double or long double.

yes,you right,but result will be as before

about Mathcad:
The concept of precision in Mathcad actually involves two different types of precision:
Internal precision, which affects how well Mathcad represents the number, and
Display precision, which controls how results appear in your worksheets.
Internal Precision
Internally, Mathcad maintains all numbers to double precision (64-bit) floating point format, as described in IEEE (Institute of Electrical and Electronics Engineers, Inc.) Standard 754, which most computer systems use.


To compute the determinant or inverse, Mathcad performs an LU decomposition of the matrix. The BLAS/LAPACK libraries from Intel are used.


P.S.I am using Mitsrosoft visual studio 2008 where double=long double


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Yahoo [Bot]