26 extern void zgetrf_ (
int *m,
int *n,
double complex* A,
int* lda,
int* ipiv,
int* info);
29 extern void zgetri_ (
int* n,
double complex* A,
int* lda,
int* ipiv,
double complex* work,
30 int* lwork,
int* info);
33 int* ipiv = (
int*) calloc (n,
sizeof(
int));
39 zgetrf_ (&n, &n, A, &n, ipiv, &info);
43 printf (
"ZGETRF argument %d had illegal argument.\n", info);
45 }
else if (info > 0) {
46 printf (
"ZGETRF failure, U is singular\n.");
51 double complex* work = (
double complex*) calloc (1,
sizeof(
double complex));
55 zgetri_ (&n, A, &n, ipiv, work, &lwork, &info);
58 lwork = (int) creal(work[0]);
59 work = (
double complex*) realloc (work, lwork *
sizeof(
double complex));
62 zgetri_ (&n, A, &n, ipiv, work, &lwork, &info);
66 printf (
"ZGETRI argument %d had illegal argument.\n", info);
68 }
else if (info > 0) {
69 printf (
"ZGETRI failure, matrix is singular\n.");
88 void linSolveComplex (
int n,
double complex* A,
double complex* B,
double complex* x) {
90 extern void zcgesv_ (
int* n,
int* nrhs,
double complex* A,
int* lda,
int* ipiv,
91 double complex* B,
int* ldb,
double complex* x,
int* ldx,
92 double complex* work,
float complex* swork,
double* rwork,
93 int* iter,
int* info);
99 double complex* work = (
double complex*) calloc (n * nrhs,
sizeof(
double complex));
102 float complex* swork = (
float complex*) calloc (n * (n + nrhs),
sizeof(
float complex));
105 double* rwork = (
double*) calloc (n,
sizeof(
double));
108 int ipiv, iter, info;
110 zcgesv_ (&n, &nrhs, A, &n, &ipiv, B, &n, x, &n, work, swork, rwork, &iter, &info);
114 printf (
"ZCGESV argument %d illegal argument.\n", info);
116 }
else if (info > 0) {
117 printf (
"ZCGESV failure, U is singular\n.");
141 void roots (
int n,
double* v,
double complex* rt) {
147 extern void dgeev_ (
char* jobvl,
char* jobvr,
int* n,
double* A,
int* lda,
148 double* wr,
double* wi,
double* vl,
int* ldvl,
double *vr,
149 int* ldvr,
double* work,
int* lwork,
int* info);
152 double *A = (
double*) calloc (m * m,
sizeof(
double));
153 memset (A, 0.0, m * m *
sizeof(
double));
155 for (
int i = 0; i < (m - 1); ++i) {
156 A[i + 1 + m * i] = 1.0;
159 for (
int i = 0; i < m; ++i) {
160 A[m * i] = -v[i + 1] / v[0];
173 double* wr = (
double*) calloc (m,
sizeof(
double));
174 double* wi = (
double*) calloc (m,
sizeof(
double));
178 dgeev_ (&job, &job, &m, A, &m, wr, wi, vl, &m, vr, &m, &wkopt, &lwork, &info);
180 work = (
double*) calloc (lwork,
sizeof(
double));
183 dgeev_ (&job, &job, &m, A, &m, wr, wi, vl, &m, vr, &m, work, &lwork, &info);
187 printf (
"DGEEV failed to compute the eigenvalues.\n");
191 for (
int i = 0; i < m; ++i) {
192 rt[i] = wr[i] + I * wi[i];
215 void svd (
int n,
double* A,
double* S,
double* U,
double* V) {
218 extern void dgesvd_ (
char* jobu,
char* jobvt,
int* m,
int* n,
double* A,
219 int* lda,
double* s,
double* u,
int* ldu,
double* vt,
220 int* ldvt,
double* work,
int* lwork,
int* info);
225 double* Vt = (
double*) calloc (n * n,
sizeof(
double));
232 dgesvd_ (&job, &job, &n, &n, A, &n, S, U, &n, Vt, &n, &wkopt, &lwork, &info);
234 work = (
double*) calloc (lwork,
sizeof(
double));
237 dgesvd_ (&job, &job, &n, &n, A, &n, S, U, &n, Vt, &n, work, &lwork, &info);
241 printf (
"DGESVD failed.\n");
246 for (
int i = 0; i < n; ++i) {
247 for (
int j = 0; j < n; ++j) {
248 V[i + j*n] = Vt[j + i*n];
void zgetri_(const int *n, double complex *A, const int *LDA, int *ipiv, double complex *work, const int *LDB, int *info)
void linSolveComplex(int n, double complex *A, double complex *B, double complex *x)
Solves the complex linear system Ax = B.
void getInverseComplex(int n, double complex *A)
Interface function to LAPACK matrix inversion subroutine.
void roots(int n, double *v, double complex *rt)
Polynomial root finding function.
void zgetrf_(const int *m, const int *n, double complex *A, const int *lda, int *ipiv, int *info)
void svd(int n, double *A, double *S, double *U, double *V)
Singular value decomposition function.