8 #define MAX(a, b) ((a)>(b)?(a):(b)) 14 static double hypot2(
double x,
double y) {
20 static void tred2(
double V[
n][
n],
double d[n],
double e[n]) {
29 for (j = 0; j <
n; j++) {
35 for (i = n-1; i > 0; i--) {
41 for (k = 0; k < i; k++) {
42 scale = scale + fabs(
d[k]);
46 for (j = 0; j < i; j++) {
55 for (k = 0; k < i; k++) {
67 for (j = 0; j < i; j++) {
73 for (j = 0; j < i; j++) {
76 g = e[j] + V[j][j] * f;
77 for (k = j+1; k <= i-1; k++) {
84 for (j = 0; j < i; j++) {
89 for (j = 0; j < i; j++) {
92 for (j = 0; j < i; j++) {
95 for (k = j; k <= i-1; k++) {
96 V[k][j] -= (f * e[k] + g *
d[k]);
107 for (i = 0; i < n-1; i++) {
112 for (k = 0; k <= i; k++) {
113 d[k] = V[k][i+1] / h;
115 for (j = 0; j <= i; j++) {
117 for (k = 0; k <= i; k++) {
118 g += V[k][i+1] * V[k][j];
120 for (k = 0; k <= i; k++) {
125 for (k = 0; k <= i; k++) {
129 for (j = 0; j <
n; j++) {
139 static void tql2(
double V[
n][
n],
double d[n],
double e[n]) {
147 double g,p,r,dl1,h,
f,tst1,eps;
148 double c,c2,c3,el1,
s,s2;
150 for (i = 1; i <
n; i++) {
157 eps = pow(2.0,-52.0);
158 for (l = 0; l <
n; l++) {
162 tst1 =
MAX(tst1,fabs(
d[l]) + fabs(e[l]));
165 if (fabs(e[m]) <= eps*tst1) {
182 p = (
d[l+1] - g) / (2.0 * e[l]);
187 d[l] = e[l] / (p + r);
188 d[l+1] = e[l] * (p + r);
191 for (i = l+2; i <
n; i++) {
205 for (i = m-1; i >= l; i--) {
215 p = c * d[i] - s * g;
216 d[i+1] = h + s * (c * g + s * d[i]);
220 for (k = 0; k <
n; k++) {
222 V[k][i+1] = s * V[k][i] + c * h;
223 V[k][i] = c * V[k][i] - s * h;
226 p = -s * s2 * c3 * el1 * e[l] / dl1;
232 }
while (fabs(e[l]) > eps*tst1);
240 for (i = 0; i < n-1; i++) {
243 for (j = i+1; j <
n; j++) {
252 for (j = 0; j <
n; j++) {
264 for (i = 0; i <
n; i++) {
265 for (j = 0; j <
n; j++) {
static void tred2(double V[n][n], double d[n], double e[n])
static void tql2(double V[n][n], double d[n], double e[n])
static double hypot2(double x, double y)
void eigen_decomposition(double A[n][n], double V[n][n], double d[n])