Esempio n. 1
0
        public static void SWAP(MatDoub x, int i, int j, int k, int l)
        {
            double t = x[i][j];

            x[i][j] = x[k][l];
            x[k][l] = t;
        }
Esempio n. 2
0
        public void inverse(MatDoub ainv)
        {
            int i, j;

            ainv.resize(n, n);
            for (i = 0; i < n; i++)
            {
                for (j = 0; j < n; j++)
                {
                    ainv[i][j] = 0.0;
                }
                ainv[i][i] = 1.0;
            }
            solve(ainv, ainv);
        }
Esempio n. 3
0
        public void solve(MatDoub b, MatDoub x)
        {
            int i, j, m = b.ncols();

            if (b.nrows() != n || x.nrows() != n || b.ncols() != x.ncols())
            {
                throw new Exception("LUdcmp::solve bad sizes");
            }
            VecDoub xx = new VecDoub(n);

            for (j = 0; j < m; j++)
            {
                for (i = 0; i < n; i++)
                {
                    xx[i] = b[i][j];
                }
                solve(xx, xx);
                for (i = 0; i < n; i++)
                {
                    x[i][j] = xx[i];
                }
            }
        }
Esempio n. 4
0
 public static void SWAP(MatDoub aMat, int ia, int ja, MatDoub bMat, int ib, int jb)
 {
     double dum = aMat[ia][ja]; aMat[ia][ja] = bMat[ib][jb]; bMat[ib][jb] = dum;
 }
Esempio n. 5
0
        public LUdcmp(MatDoub a)
        {
            n    = (a.nrows());
            lu   = (a);
            aref = (a);
            indx = new VecInt(n);
            const double TINY = 1.0e-40;
            int          i, imax = int.MinValue, j, k;
            double       big, temp;
            VecDoub      vv = new VecDoub(n);

            d = 1.0;

            for (i = 0; i < n; i++)
            {
                big = 0.0;
                for (j = 0; j < n; j++)
                {
                    if ((temp = Math.Abs(lu[i][j])) > big)
                    {
                        big = temp;
                    }
                }
                if (big == 0.0)
                {
                    throw new Exception("Singular matrix in LUdcmp");
                }
                vv[i] = 1.0 / big;
            }
            for (k = 0; k < n; k++)
            {
                big = 0.0;
                for (i = k; i < n; i++)
                {
                    temp = vv[i] * Math.Abs(lu[i][k]);
                    if (temp > big)
                    {
                        big  = temp;
                        imax = i;
                    }
                }
                if (k != imax)
                {
                    for (j = 0; j < n; j++)
                    {
                        temp        = lu[imax][j];
                        lu[imax][j] = lu[k][j];
                        lu[k][j]    = temp;
                    }
                    d        = -d;
                    vv[imax] = vv[k];
                }
                indx[k] = imax;
                if (lu[k][k] == 0.0)
                {
                    lu[k][k] = TINY;
                }
                for (i = k + 1; i < n; i++)
                {
                    temp = lu[i][k] /= lu[k][k];
                    for (j = k + 1; j < n; j++)
                    {
                        lu[i][j] -= temp * lu[k][j];
                    }
                }
            }
        }