示例#1
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];
                }
            }
        }
示例#2
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];
                    }
                }
            }
        }