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

wrong SparseLU solution by Eigen

Tags: None
(comma "," separated)
hipkh
Registered Member
Posts
4
Karma
0

wrong SparseLU solution by Eigen

Wed Jun 11, 2014 8:53 am
I have solved the system of linear equations by Eigen library with SparseLU solver. The same system was solved in Matlab.
I get different solutions. I think Matlab solves correctly since some values of the solution vector must be symmetric.

A x = b
Code: Select all
Eigen::SparseLU<SparseMatrix, Eigen::COLAMDOrdering<SparseMatrix::Index> > solver;
solver.analyzePattern(A);
solver.factorize(A);
Eigen::VectorXd x = solver.solve(b);


Matrix A:
576.923 -384.615 -288.462 -240.385 96.1538 -48.0769 0 0 0 0 0 0
-384.615 1153.85 192.308 0 -288.462 240.385 -384.615 -288.462 -240.385 0 0 0
-288.462 192.308 2307.69 5.68434e-014 -769.231 -7.10543e-015 -288.462 -769.231 -4.9738e-014 -288.462 192.308 -288.462
-240.385 -7.10543e-015 5.68434e-014 2307.69 0 192.308 240.385 -4.9738e-014 192.308 -240.385 -7.10543e-015 240.385
96.1538 -288.462 -769.231 0 1153.85 0 0 0 0 0 -288.462 96.1538
-48.0769 240.385 -7.10543e-015 192.308 0 1153.85 0 0 0 0 -240.385 48.0769
0 -384.615 -288.462 240.385 0 0 576.923 96.1538 48.0769 0 0 0
0 -288.462 -769.231 -7.10543e-014 0 0 96.1538 1153.85 2.84217e-014 96.1538 -288.462 0
0 -240.385 -4.9738e-014 192.308 0 0 48.0769 5.68434e-014 1153.85 -48.0769 240.385 0
0 0 -288.462 -240.385 0 0 0 96.1538 -48.0769 576.923 -384.615 0
0 0 192.308 0 -288.462 -240.385 0 -288.462 240.385 -384.615 1153.85 -384.615
0 0 -288.462 240.385 96.1538 48.0769 0 0 0 0 -384.615 576.923

Matrix b:
0
0
0
1346.15
288.462
673.077
0
-288.462
673.077
-288.462
0
288.462

Solution from SparseLU :
-0.339286
-0.553571
-0.553571
0.5
-0.339286
0.5
-0.767857
-0.767857
0.5
-0.767857
-0.553571
-0.339286

Solution from Matlab:
0.2143
-0.0000
-0.0000
0.5000
0.2143
0.5000
-0.2143
-0.2143
0.5000
-0.2143
-0.0000
0.2143

Why this solver solves not correctly?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
I checked your numbers and the residuals are 1e-6 and 1e-5 for SparseLU and Mathlab respectively. These high residuals are probably due to rounding when printing the values. If I recompute a solution with SparseLU I get a residual of 1e-16 with the following solution:

0.214285 1.01935e-11 1.01937e-11 0.499999 0.214285 0.499998 -0.214285 -0.214285 0.499998 -0.214287 1.01938e-11 0.214287
hipkh
Registered Member
Posts
4
Karma
0
Thanks for the answer.
I have tried it again and it works.

But I have compiled C++ project to DLL to use it in Java. I pass matrices by jna. In C++ code I output the matrices and solution and I get wrong results. Is it problem with jna or dll?


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]