/* matroot.c - calculate the square root of a matrix * * Copyright (C) 2004 Jochen Voss. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * $Id: matroot.c 7208 2006-09-03 16:11:08Z voss $ */ #include #include #include #include #include static const int N = 7; static void set_entry(double *A, int i, int j, double val) { A[j*N+i] = val; } static double get_entry(const double *A, int i, int j) { return A[j*N+i]; } static int dsyevr(char JOBZ, char RANGE, char UPLO, int N, double *A, int LDA, double VL, double VU, int IL, int IU, double ABSTOL, int *M, double *W, double *Z, int LDZ, int *ISUPPZ, double *WORK, int LWORK, int *IWORK, int LIWORK) { extern void dsyevr_(char *JOBZp, char *RANGEp, char *UPLOp, int *Np, double *A, int *LDAp, double *VLp, double *VUp, int *ILp, int *IUp, double *ABSTOLp, int *Mp, double *W, double *Z, int *LDZp, int *ISUPPZ, double *WORK, int *LWORKp, int *IWORK, int *LIWORKp, int *INFOp); int INFO; dsyevr_(&JOBZ, &RANGE, &UPLO, &N, A, &LDA, &VL, &VU, &IL, &IU, &ABSTOL, M, W, Z, &LDZ, ISUPPZ, WORK, &LWORK, IWORK, &LIWORK, &INFO); return INFO; } static double dlamch(char CMACH) { extern double dlamch_(char *CMACHp); return dlamch_(&CMACH); } int main() { double *A, *B, *W, *Z, *WORK; int *ISUPPZ, *IWORK; int i, j; int M; /* allocate and initialise the matrix */ A = malloc(N*N*sizeof(double)); for (i=0; i