318 int i, j, k, iq, ip, numPos;
319 Real tresh, theta, tau, t, sm, s, h, g, c, tmp;
320 Real bspace[MAX_SCRATCH_ARRAY_SIZE], zspace[MAX_SCRATCH_ARRAY_SIZE];
321 Real* b = (n <= MAX_SCRATCH_ARRAY_SIZE) ? bspace :
new Real[n];
322 Real* z = (n <= MAX_SCRATCH_ARRAY_SIZE) ? zspace :
new Real[n];
325 for (ip = 0; ip < n; ip++) {
326 for (iq = 0; iq < n; iq++) {
331 for (ip = 0; ip < n; ip++) {
332 b[ip] = w[ip] = a(ip, ip);
337 for (i = 0; i < MAX_ROTATIONS; ++i) {
339 for (ip = 0; ip < n - 1; ip++) {
340 for (iq = ip + 1; iq < n; iq++) {
341 sm += std::abs(a(ip, iq));
344 if (sm == 0.0) {
break; }
347 tresh = 0.2 * sm / (n * n);
352 for (ip = 0; ip < n - 1; ip++) {
353 for (iq = ip + 1; iq < n; iq++) {
354 g = 100.0 * std::abs(a(ip, iq));
357 if (i > 3 && (std::abs(w[ip]) + g) == std::abs(w[ip]) &&
358 (std::abs(w[iq]) + g) == std::abs(w[iq])) {
360 }
else if (std::abs(a(ip, iq)) > tresh) {
362 if ((std::abs(h) + g) == std::abs(h)) {
365 theta = 0.5 * h / (a(ip, iq));
366 t = 1.0 / (std::abs(theta) + std::sqrt(1.0 + theta * theta));
367 if (theta < 0.0) { t = -t; }
369 c = 1.0 / std::sqrt(1 + t * t);
380 for (j = 0; j <= ip - 1; ++j) {
381 ROTATE(a, j, ip, j, iq);
384 for (j = ip + 1; j <= iq - 1; ++j) {
385 ROTATE(a, ip, j, j, iq);
388 for (j = iq + 1; j < n; ++j) {
389 ROTATE(a, ip, j, iq, j);
391 for (j = 0; j < n; ++j) {
392 ROTATE(v, j, ip, j, iq);
398 for (ip = 0; ip < n; ip++) {
406 if (i >= MAX_ROTATIONS) {
407 std::cout <<
"SquareMatrix::Jacobi: Error extracting eigenfunctions"
409 if (n > MAX_SCRATCH_ARRAY_SIZE) {
417 for (j = 0; j < n - 1; ++j) {
420 for (i = j + 1; i < n; ++i) {
429 for (i = 0; i < n; i++) {
440 int ceil_half_n = (n >> 1) + (n & 1);
441 for (j = 0; j < n; ++j) {
442 for (numPos = 0, i = 0; i < n; ++i) {
443 if (v(i, j) >= 0.0) { numPos++; }
445 if (numPos < ceil_half_n) {
446 for (i = 0; i < n; ++i) {
452 if (n > MAX_SCRATCH_ARRAY_SIZE) {