I want to find a solution for $xA=0$, where $A$ is a square matrix. I know that most of the LAPACK routines solve for $Ax=b$. So I take $A^T$ as a, and set $b=0$. I have an additional restriction of $\Sigma x=1$.Thus, I add an additional row of $ones$ to $A^T$ and a single $one$ to $b$. This also allows to avoid the trivial solution in which $x=0$.
This approach works fine in Octave, but I am struggling to implement this with LAPACK. I keep getting info=4
, which means that my fourth factor $U$ in the $LU$ factorization of $A^T$ with a row of $ones$ is singular. This is happening because my last row is $ones$.
Is there a good way to solve $xA=0$? I should add that in my real data, $A$ is sparse.
Here is my failing attempt in C, where b=[0,0,0,1]
.
float *A, *b;
/* Ax = b
* Ax = xT(A) //transpose
* A is m x m //matrix
* b is m x 1 //vector
* x is m x 1 //vector
*/
int m = 3;
int scale = 1;
A = (float *)mkl_malloc(m*m,32);
A[0]=-5;A[1]= 2;A[2]= 3;
A[3]= 4;A[4]= -10;A[5]= 6;
A[6]= 7;A[7]=8;A[8]= -15;
b = (float*)mkl_malloc(m+1,32);
for (int i = 0; i < m; i++) {
b[i]=0.0;
}
b[m]=1.0;
int matrix_order = LAPACK_ROW_MAJOR;
int ipiv[m+1];
int info;
//transpose and add a row of ones
float * Acopy = (float*)mkl_malloc((m+1)*m,32);
mkl_somatcopy('R','T',m,m,scale,A,m,Acopy,m);
//assign last row of ones
for (int i = 0; i < m; i++){
int p = m*m+i;
Acopy[p]=1.0;
}
printf("Original\n");
print_matrix(A, m, m );
printf("Transpose with ones\n");
print_matrix(Acopy, m+1, m );
info = LAPACKE_sgesv(matrix_order,m+1,1,Acopy,m+1,ipiv,b,1);
printf("$?=%d\n",info);
print_matrix(b, m+1, 1 );
return 0;
Thank you.
/opt/intel/compilers_and_libraries_2017/<YOUR_PLATFORM_HERE>/mkl/examples/solverc/source/
). $\endgroup$