2

I want to solve a system of linear equations (SLE, Ax=b, where A consists out of 8 rows and columns) but this system will always have infinite solutions. Many people refer to Eigen, when it comes down to solving system of linear equations. However, as a result it would be great if I have some kind of "dependencies" between the variables, so that I just need to set the values of the free variables and get the results. E.g:

x1 = 5.234*x2 + 2.3232x3
x2 = 3.234 + 1.3*x3
x3 = free.

I looked in the Eigen documentation but they don't mention SLEs with infinite many solutions. Is Eigen capable of doing this kindof calculation or is there a better library?

Regards

EDIT:

The system could look like

0.4*f1+0.0*f2+0.6*f3+0.0*f4+0.0*f5+0.0*f6+0.0*f7+0.0*f8= fx
0.0*f1+0.4*f2+0.0*f3+0.6*f4+0.0*f5+0.0*f6+0.0*f7+0.0*f8= fx
0.0*f1+0.0*f2+0.0*f3+0.0*f4+0.3*f5+0.0*f6+0.7*f7+0.0*f8= fx
0.0*f1+0.0*f2+0.0*f3+0.0*f4+0.0*f5+0.0*f6+0.5*f7+0.5*f8= fx
0.0*f1+0.0*f2+0.0*f3+0.0*f4+0.0*f5+0.0*f6+0.0*f7+0.0*f8= fx
0.0*f1+0.0*f2+0.0*f3+0.0*f4+0.0*f5+0.0*f6+0.0*f7+0.0*f8= fx
0.0*f1+0.0*f2+0.0*f3+0.0*f4+0.0*f5+0.0*f6+0.0*f7+0.0*f8= fx
0.0*f1+0.0*f2+0.0*f3+0.0*f4+0.0*f5+0.0*f6+0.0*f7+0.0*f8= fx

Where the number of rows with coefficients of only zero may vary and fx is an arbitrary value. The trivial solution f1=f2=f3=f4=f5=f6=F7=f8=fx=0 cannot be used. I could repeat rows in order to get rid of the rows with empty coefficients.

  • If the rank of the matrix is too low, Eigen fails AFAIK. Then your subsequent question is out of scope for SO. – Matthieu Brucher Jan 28 '19 at 12:38
  • Maybe look at Armadillo library – Ashkan Jan 28 '19 at 12:39
  • 2
    I'm probably missing something here. If you have too many variables and too few equations, you have infinite solutions, but _for linear equations_ those will form a hyperplane. By picking values for free variables, you take the intersection of that hyperplane with another (axis-aligned) hyperplane. By picking enough free variables, you are left with a single point which is your single solution.. – MSalters Jan 28 '19 at 12:42
  • 1
    Also, while you mention an 8x8 matrix, your example is 3x2. That's why you have a free variable. If you need just _a_ solution, substitute x3=0. That's usually the easiest solution. – MSalters Jan 28 '19 at 12:46
  • You mean, that I start picking values for free variables, then check if I can fulfill one equation and continue? Let's say I choose an arbitrary value for fx and one for f8. The I could already solve equation 5 with f4*0.3+0.7*f8 = fx. The I continue with an abritrary value for f7 and so forth? – user3884995 Jan 28 '19 at 13:10
  • If there is an infinite number of solutions, you need 1. to get one solution (e.g. with pseudo-inverse) and 2. to get a basis of Ker A. All the solutions are provided by the first solution + linear function of the basis – Damien Jan 28 '19 at 13:11

1 Answers1

3

If x1 and x2 are two solutions, then A(x1 - x2) = 0, i.e. the vector x1 -x2 owns to the null-space of A (the kernel Ker A).

Therefore, if x0 is a particular solution and if the v[i] form a basis of Ker A, then the set of all solutions is provided by:

x = x0 + sum_i a[i] v[i], where a[i] are any real numbers

In Eigen, some decompositions are rank-revealing, e.g. FullPivLU.

According to Eigen site, you can get a basis of the kernel with for example:

Matrix3f A;
.......
FullPivL<Matrix3f> lu_decomp(A);
auto K = lu_decomp.kernel();

As FullPivLU has a solver, you should get one particular solution with:

lu_decomp.solve (...);
Damien
  • 4,809
  • 4
  • 15
  • 20