CALL DGETRF( M, N, A, LDA, IPIV, INFO )
CALL DGETRI( N, A, LDA, IPIV, WORK, LWORK, INFO )
// _dim is the dimension of the matrix
// _uplo is a pointer to the character 'L'
// _A is a pointer the array of matrix data
int info;
int* ipiv = new int [ _dim ];
double* work = new double [ _dim ];
DSYTRF( _uplo , &_dim , _A , &_dim , ipiv , work , &_dim , &info );
if( info != 0 )
{
cout << "Step 1 | DSYTRF failed ..." << endl;
return info;
}
int lwork = (int) work[0];
double* nwork = new double [ lwork ];
DSYTRI( _uplo , &_dim , _A , &_dim , ipiv , nwork , &info );
return info;
int lwork = (int) work[0];
double* nwork = new double [ lwork ];
double* nwork = new double [ _dim ];
#include <stdlib.h>
#include <stdio.h>
extern void dsytrf_( char *uplo, int *n, double *a, int *lda, int *ipiv, double *work, int *lwork, int *info );
extern void dsytri_( char *uplo, int *n, double *a, int *lda, int *ipiv, double *work, int *info );
int main (){
double *A;
double *work;
int *ipiv;
int info, lwork;
int n=7;
A = (double *) malloc(49 * sizeof (double));
ipiv = (int *) malloc(7 * sizeof (int));
A[ 0]= 0.000000; A[ 7]= 0xDEADBEEF; A[14]= 0xDEADBEEF; A[21]= 0xDEADBEEF; A[28]=0xDEADBEEF; A[35]= 0xDEADBEEF; A[42]= 0xDEADBEEF;
A[ 1]= 529.831737; A[ 8]= 0.000000; A[15]= 0xDEADBEEF; A[22]= 0xDEADBEEF; A[29]=0xDEADBEEF; A[36]= 0xDEADBEEF; A[43]= 0xDEADBEEF;
A[ 2]=1198.292909; A[ 9]= 529.831737; A[16]= 0.000000; A[23]= 0xDEADBEEF; A[30]=0xDEADBEEF; A[37]= 0xDEADBEEF; A[44]= 0xDEADBEEF;
A[ 3]= 529.831737; A[10]=1198.292909; A[17]= 529.831737; A[24]= 0.000000; A[31]=0xDEADBEEF; A[38]= 0xDEADBEEF; A[45]= 0xDEADBEEF;
A[ 4]= 1.000000; A[11]= 1.000000; A[18]= 1.000000; A[25]= 1.000000; A[32]= 0.000000; A[39]= 0xDEADBEEF; A[46]= 0xDEADBEEF;
A[ 5]= 10.000000; A[12]= 0.000000; A[19]= -10.000000; A[26]= 0.000000; A[33]= 0.000000; A[40]= 0.000000; A[47]= 0xDEADBEEF;
A[ 6]= 0.000000; A[13]= 10.000000; A[20]= 0.000000; A[27]= -10.000000; A[34]= 0.000000; A[41]= 0.000000; A[48]= 0.000000;
lwork = -1;
work = (double *) malloc(1 * sizeof (double));
dsytrf_( "L", &n, A, &n, ipiv, work, &lwork, &info );
lwork = (int) work[0];
free(work);
work = (double *) malloc(lwork * sizeof (double));
dsytrf_( "L", &n, A, &n, ipiv, work, &lwork, &info );
free(work);
work = (double *) malloc(n * sizeof (double));
dsytri_( "L", &n, A, &n, ipiv, work, &info );
free(work);
int i,j;
for (i=0;i<7;i++) { for (j=0;j<=i;j++) printf("%14.7f ",A[i+j*7]); printf("\n"); }
free(ipiv);
free(A);
return 0;
}
Here's related question. Would DSPSV be the correct routine to use in solving linear systems Ax = b, where A is a positive semidefinite matrix -- the sort I'm trying to invert, that has zeros along its diagonal e.g. in the original post.
Julien Langou wrote:
- Code: Select all
...
A[ 0]= 0.000000; A[ 7]= 0xDEADBEEF; A[14]= 0xDEADBEEF; A[21]= 0xDEADBEEF; A[28]=0xDEADBEEF; A[35]= 0xDEADBEEF; A[42]= 0xDEADBEEF;
A[ 1]= 529.831737; A[ 8]= 0.000000; A[15]= 0xDEADBEEF; A[22]= 0xDEADBEEF; A[29]=0xDEADBEEF; A[36]= 0xDEADBEEF; A[43]= 0xDEADBEEF;
A[ 2]=1198.292909; A[ 9]= 529.831737; A[16]= 0.000000; A[23]= 0xDEADBEEF; A[30]=0xDEADBEEF; A[37]= 0xDEADBEEF; A[44]= 0xDEADBEEF;
A[ 3]= 529.831737; A[10]=1198.292909; A[17]= 529.831737; A[24]= 0.000000; A[31]=0xDEADBEEF; A[38]= 0xDEADBEEF; A[45]= 0xDEADBEEF;
A[ 4]= 1.000000; A[11]= 1.000000; A[18]= 1.000000; A[25]= 1.000000; A[32]= 0.000000; A[39]= 0xDEADBEEF; A[46]= 0xDEADBEEF;
A[ 5]= 10.000000; A[12]= 0.000000; A[19]= -10.000000; A[26]= 0.000000; A[33]= 0.000000; A[40]= 0.000000; A[47]= 0xDEADBEEF;
A[ 6]= 0.000000; A[13]= 10.000000; A[20]= 0.000000; A[27]= -10.000000; A[34]= 0.000000; A[41]= 0.000000; A[48]= 0.000000;
...
Julien Langou wrote:For your matrix, which is symmetric indefinite, you can either use DSYTRF+DSYTRS (and the combo driver is named DSYSV, so DSYSV=DSYTRF+DSYTRS). This is when you want to store your matrix in full format. I.e.: storing the symmetric matrix requires n^2 data storage. (See the code in the previous post where I needed 49 entries for a 7x7 symmetric matrix.) If you want to save space, you can use the packed storage. The storage is then the minimum n*(n+1)/2 (so about n^2/2, for 7x7 would be 28 instead of 49). (See data storage in the header of the subroutine.) The name of the subroutines are now DSPTRF+DSPTRS (and combo driver is named DSPSV, so DSPSV=DSPTRF+DSPTRS). You can also compute inverses in both of these formats. Note: SP routines save half the space but are NOTICEABLY slower than their SY counterparts. So if space is not an issue, stick with full format and the SY subroutines.Here's related question. Would DSPSV be the correct routine to use in solving linear systems Ax = b, where A is a positive semidefinite matrix -- the sort I'm trying to invert, that has zeros along its diagonal e.g. in the original post.
Just to confirm, DGESV would be the driver to use in order to solve an un-symmetric matrix (having zeros along its diagonal).
I've been creating a matrix of from an array whose length equal to the number of initialized elements!!! (This explains the triangular monstrosities in my earlier post.)
Users browsing this forum: Bing [Bot], fgdgfda52x, Google [Bot] and 3 guests