How can we get the matrix L and U of A from dgbtrf_( ), thank you.
When I use dgbtrf_(&N,&N,&KL,&KU,AB,&LDAB,IPIV,&INFO) to get matrix L and U from A. I get the result of U, it is seems incorrect, How can we get the matrix L and U of A from dgbtrf_( ), thank you. Matrix A [3][3] is: 7 9 0 4 5 7 0 4 10
Array AB_1[4][3] is: 0 0 0 0 9 7 7 5 10 4 4 0 0 0 7 4 0 9 5 4 0 7 10 0 After use dgbtrf_(), we can get AB is blow. 0.00 0.00 7.00 0.57 0.00 9.00 4.00 -0.04 0.00 10.00 7.36 0.00
the U result 7.0000 9.0000 0.0000 0.0000 4.0000 10.0000 0.0000 0.0000 7.3571 but infact U should be U=[7 9 0 0 -1/7 7 0 0 206];
test.c #include <stdio.h> int main() { int DIM=3,i,j,k; double A[3][3]={7,9,0,4,5,7,0,4,10},AB_1[4][3]={0,0,0,0,9,7,7,5,10,4,4,0},AB[12],U[3][3]; //band matrix A is //7 9 0 //4 5 7 //0 4 10
int IPIV[3]; int M=3,N=3, KL=1, KU=1, NRHS=1, LDB=3, INFO; int LDAB=2*KL+KU+1;
printf("Matrix A [%d][%d] is:\n", M, N);
for (i = 0; i < M; ++i)
{
for (j = 0; j < N; ++j)
{
printf("%.f\t", A[i][j]);
}
printf("\n");
}
printf("\n");
printf("Array AB_1[%d][%d] is:\n",2*KL + KU + 1, N);
for(i=0;i<2*KL+KU+1;i++)
{
for (j = 0; j < N; j++)
{
printf("%.f\t", AB_1[i][j]);
}
printf("\n");
}
k=0; for(j=0;j<N;j++) for(i=0;i<2KL+KU+1;i++) {AB[k]=AB_1[i][j]; k=k+1; } for(i=0;i<(2KL+KU+1)*N;i++) printf("%.f ",AB[i]); printf("\n");
dgbtrf_(&N,&N,&KL,&KU,AB,&LDAB,IPIV,&INFO); printf("After use dgbtrf_(), we can get AB is blow.\n"); for(i=0;i<(2*KL+KU+1)*N;i++) printf("%.2f ",AB[i]); printf("\n"); U[0][0]=AB[2],U[0][1]=AB[5],U[0][2]=AB[8],U[1][1]=AB[6],U[1][2]=AB[9],U[2][2]=AB[10]; printf("\nthe U result\n"); for(i=0;i<3;i++) {for(j=0;j<3;j++) printf("%.4f ",U[i][j]); printf("\n"); } }
The U you expect is the solution without pivoting A = LU. DGBTRF computes the LU factorization with partial pivoting, i.e., PA = LU, and the computed solution is correct.
Your code extracts U correctly from the output of DGBTRF. If you want L and U explicitly anyway, consider using DGETRF to avoid conversions between band storage and dense storage.