iphone - Is it possible to solve a non-square under/over constrained matrix using Accelerate/LAPACK? -


is possible solve non-square under/over constrained matrix using accelerate/lapack? such following 2 matrices. if variables under constrained should equal 0 instead of being infinite.

so in under constrained case: a, d & e equal 0, while b, c & f equal -1.

in on constrained case variables equal -1.

under constrained:

 ____                        ____ | (a) (b) (c) (d) (e) (f)        | | -1   0   0   1   0   0   |  0  | |  1   0   0   0  -1   0   |  0  | |  0  -1   1   0   0   0   |  0  | |  0   1   0   0   0  -1   |  0  | |  0   1   0   0   0   0   | -1  | |____                        ____| 

over constrained:

 ____                        ____ |                                | | -1   0   0   1   0   0   |  0  | |  1   0   0   0  -1   0   |  0  | |  0  -1   1   0   0   0   |  0  | |  0   1   0   0   0  -1   |  0  | |  0   1   0   0   0   0   | -1  | |  0   0   1  -1   0   0   |  0  | |  1  -1   0   0   0   0   |  0  | |____                        ____| 

yes!

void solveunderdeterminedsystem() {      __clpk_integer m = 5;     __clpk_integer n = 6;     __clpk_integer nrhs = 1;     double a[30] = {         -1.0,  1.0,  0.0,  0.0,  0.0,          0.0,  0.0, -1.0,  1.0,  1.0,          0.0,  0.0,  1.0,  0.0,  0.0,          1.0,  0.0,  0.0,  0.0,  0.0,          0.0, -1.0,  0.0,  0.0,  0.0,          0.0,  0.0,  0.0, -1.0,  0.0     };     __clpk_integer lda = 5;     double x[6] = { 0.0, 0.0, 0.0, 0.0, -1.0, 0.0 };     __clpk_integer ldb = 6;     /* need allocate @ least 2*min(m,n) workspace. */     double work[12];     __clpk_integer worksize = 12;     __clpk_integer info;      dgels_("n", &m, &n, &nrhs, a, &lda, x, &ldb, work, &worksize, &info);      if (info)         printf("could not solve system; dgels exited error %d\n", info);     else         printf("solution [%f, %f, %f, %f, %f, %f]\n",                x[0], x[1], x[2], x[3], x[4], x[5]); } 

the same routine solve over-determined systems in least-squares sense (the result minimizer of residual ||ax - b||).

note dgels_ assumes matrix has full rank (i.e., rank(a) = min(m, n)). if not case, need use different routine (dgelsd_) uses svd factorization instead of qr.

you seem asking lot of questions lapack. worth time read the documentation.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -