Re: [ojAlgo-user] ActiveSetSolver - RuntimeException: Matrix is singular.
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Anders P. <an...@op...> - 2008-10-14 14:02:59
|
If you use PrimitiveMatrix.FACTORY instead of JamaMatrix.FACTORY your code will run successfully and produce a solution that is the same as the one you got from Matlab (within 4 decimals). The reason is that PrimitiveMatrix, BigMatrix & ComplexMatrix (the "native" ojAlgo matrices) are more intelligent in solving equation systems than JamaMatrix. Look at the implementations of BasicMatrix#solve() and you'll see what I mean. /Anders 14 okt 2008 kl. 12.56 skrev Oddvar Grønning: > Hi, > > > > I’m trying to solve some quadratic programming systems using > version 24. The ActiveSetSolver does not always converge to a > solution, but throws an exception, “Matrix is singular” (The > exception is thrown by org.ojalgo.matrix.jama.LUDecomposition). > > The thing is that if I run Matlabs quadprog method on the exact > same system, a solution is found without problems. Here is the code > that produces the exception: > > > > public class QPTest { > > > > public static void main(String[] args) { > > new QPTest(); > > } > > > > public QPTest() { > > > > BasicMatrix[] system = new BasicMatrix[6]; > > //{[AE], [be], [Q], [c], [AI], [bi]} > > > > double[][] AE = new double[][] > {{-0.0729971273939726,-0.31619624199405116,-0.14365990081105298,-3.491 > 4813388431334E-15,0.9963066090106673,0.9989967493404447,1.0,0.0,0.0}, > {-2.5486810808521023E-16,3.6687950405257466,3.2047109656515507,1.0,0.0 > 8586699506600544,0.04478275122437895,0.0,1.0,0.0}, > {-7.646043242556307E-15,-107.21808503782593,-97.434268076846,30.0,-11. > 54276933307617,7.647488207332634,0.0,0,1.0}}; > > system[0] = JamaMatrix.FACTORY.copy > (AE); // AE > > system[1] = JamaMatrix.FACTORY.copy(new > double[][]{{10.461669614447484}, {-0.5328532701990767}, > {15.782527136201711}}); // be > > system[2] = JamaMatrix.FACTORY.buildEye(9, > 9); // Q > > system[2] = system[2].set(3, 3, 10); > > system[2] = system[2].set(4, 4, 10); > > system[2] = system[2].set(5, 5, 10); > > system[2] = system[2].set(6, 6, 1000000000); > > system[2] = system[2].set(7, 7, 1000000000); > > system[2] = system[2].set(8, 8, 1000000000); > > system[3] = JamaMatrix.FACTORY.copy(new > double[][]{{0}, {0}, {0}, {1}, {1}, {1}, {0}, {0}, > {0}}); // c > > > > double[][] Ain = new double[18][9]; > > > > for(int i = 0; i < 9; i++) { > > Ain[i][i] = 1; > > Ain[i+9][i] = -1; > > } > > system[4] = JamaMatrix.FACTORY.copy > (Ain); // AI > > > > double[][] bin = new double[][]{{0}, > {0.0175}, {0.0175}, {5}, {5}, {5}, {100000}, {100000}, {100000}, > {0}, {0.0175}, {0.0175}, {5}, {5}, {5}, {100000}, {100000}, {100000}}; > > system[5] = JamaMatrix.FACTORY.copy > (bin); // bi > > > > ActiveSetSolver as = new ActiveSetSolver > (system); > > Result res = as.solve(); > > } > > } > > > > Am I doing something wrong? Bug? > > > > Matlab is returning: > > X = > > > > 0.00000000000000 > > -0.01750000000000 > > -0.01750000000000 > > 0.88830035195990 > > 4.56989525276369 > > 5.00000000000000 > > 0.90562154243124 > > -1.91718419629399 > > 0.06390614020590 > > > > - Oddvar > > ---------------------------------------------------------------------- > --- > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win > great prizes > Grand prize is a trip for two to an Open Source event anywhere in > the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user |