1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
/* atou1.c CCMATH mathematics library source code.
*
* Copyright (C) 2000 Daniel A. Atkinson All rights reserved.
* This code may be redistributed under the terms of the GNU library
* public license (LGPL). ( See the lgpl.license file for details.)
* ------------------------------------------------------------------------
*/
#include <stdlib.h>
void atou1(double *a, int m, int n)
{
double *p0, *p, *q, *w;
int i, j, k, mm;
double s, h;
w = (double *)calloc(m, sizeof(double));
p0 = a + n * n - 1;
i = n - 1;
mm = m - n;
if (mm == 0) {
*p0 = 1.;
p0 -= n + 1;
--i;
++mm;
}
for (; i >= 0; --i, ++mm, p0 -= n + 1) {
if (*p0 != 0.) {
for (j = 0, p = p0 + n; j < mm; p += n)
w[j++] = *p;
h = *p0;
*p0 = 1. - h;
for (j = 0, p = p0 + n; j < mm; p += n)
*p = -h * w[j++];
for (k = i + 1, q = p0 + 1; k < n; ++k) {
for (j = 0, p = q + n, s = 0.; j < mm; p += n)
s += w[j++] * *p;
s *= h;
for (j = 0, p = q + n; j < mm; p += n)
*p -= s * w[j++];
*q++ = -s;
}
}
else {
*p0 = 1.;
for (j = 0, p = p0 + n, q = p0 + 1; j < mm; ++j, p += n)
*p = *q++ = 0.;
}
}
free(w);
}
|