8 #define MAX(a, b) ((a)>(b)?(a):(b))
13 static double hypot2(
double x,
double y) {
19 static void tred2(
double V[
n][
n],
double d[
n],
double e[
n]) {
28 for (j = 0; j <
n; j++) {
34 for (i =
n-1; i > 0; i--) {
40 for (k = 0; k < i; k++) {
41 scale = scale + fabs(d[k]);
45 for (j = 0; j < i; j++) {
54 for (k = 0; k < i; k++) {
66 for (j = 0; j < i; j++) {
72 for (j = 0; j < i; j++) {
75 g = e[j] + V[j][j] * f;
76 for (k = j+1; k <= i-1; k++) {
83 for (j = 0; j < i; j++) {
88 for (j = 0; j < i; j++) {
91 for (j = 0; j < i; j++) {
94 for (k = j; k <= i-1; k++) {
95 V[k][j] -= (f * e[k] + g * d[k]);
106 for (i = 0; i <
n-1; i++) {
111 for (k = 0; k <= i; k++) {
112 d[k] = V[k][i+1] / h;
114 for (j = 0; j <= i; j++) {
116 for (k = 0; k <= i; k++) {
117 g += V[k][i+1] * V[k][j];
119 for (k = 0; k <= i; k++) {
124 for (k = 0; k <= i; k++) {
128 for (j = 0; j <
n; j++) {
138 static void tql2(
double V[
n][
n],
double d[
n],
double e[
n]) {
146 double g,p,r,dl1,h,f,tst1,eps;
147 double c,c2,c3,el1,s,s2;
149 for (i = 1; i <
n; i++) {
156 eps = pow(2.0,-52.0);
157 for (l = 0; l <
n; l++) {
161 tst1 =
MAX(tst1,fabs(d[l]) + fabs(e[l]));
164 if (fabs(e[m]) <= eps*tst1) {
181 p = (d[l+1] - g) / (2.0 * e[l]);
186 d[l] = e[l] / (p + r);
187 d[l+1] = e[l] * (p + r);
190 for (i = l+2; i <
n; i++) {
204 for (i = m-1; i >= l; i--) {
214 p =
c * d[i] - s * g;
215 d[i+1] = h + s * (
c * g + s * d[i]);
219 for (k = 0; k <
n; k++) {
221 V[k][i+1] = s * V[k][i] +
c * h;
222 V[k][i] =
c * V[k][i] - s * h;
225 p = -s * s2 * c3 * el1 * e[l] / dl1;
231 }
while (fabs(e[l]) > eps*tst1);
239 for (i = 0; i <
n-1; i++) {
242 for (j = i+1; j <
n; j++) {
251 for (j = 0; j <
n; j++) {
263 for (i = 0; i <
n; i++) {
264 for (j = 0; j <
n; j++) {