4 #include <grass/gmath.h>
8 static int egcmp(
const void *pa,
const void *pb);
38 for (i = 0; i <
n; i++)
39 for (j = 0; j <
n; j++)
47 for (i = 0; i <
n; i++)
48 for (j = 0; j <
n; j++)
49 Vectors[i][j] = a[i][j];
78 buff = (
double *)G_malloc(bands * (bands + 1) *
sizeof(double));
79 tmp = (
double **)G_malloc(bands *
sizeof(
double *));
80 for (i = 0; i < bands; i++)
81 tmp[i] = &buff[i * (bands + 1)];
84 for (i = 0; i < bands; i++) {
85 for (j = 0; j < bands; j++)
86 tmp[i][j + 1] = z[j][i];
91 qsort(tmp, bands,
sizeof(
double *), egcmp);
94 for (i = 0; i < bands; i++) {
95 for (j = 0; j < bands; j++)
96 z[j][i] = tmp[i][j + 1];
124 for (i = 0; i < bands; i++)
125 for (j = 0; j < i; j++) {
126 double tmp = eigmat[i][j];
128 eigmat[i][j] = eigmat[j][i];
136 static int egcmp(
const void *pa,
const void *pb)
138 const double *a = *(
const double *
const *)pa;
139 const double *
b = *(
const double *
const *)pb;
void G_free(void *buf)
Free allocated memory.
int eigen(double **M, double **Vectors, double *lambda, int n)
Computes eigenvalues (and eigen vectors if desired) for symmetric matices.
double ** G_alloc_matrix(int rows, int cols)
Matrix memory allocation.
int egvorder2(double *d, double **z, long bands)
Returns 0.
void G_free_vector(double *v)
Vector memory deallocation.
void G_free_matrix(double **m)
Matrix memory deallocation.
int transpose2(double **eigmat, long bands)
Returns 0.
double * G_alloc_vector(size_t n)
Vector matrix memory allocation.