Exemplo n.º 1
0
        public object Clone()
        {
            SkylineMatrix2D <T> clone = new SkylineMatrix2D <T>(this.rowIndex);

            this.data.CopyTo(clone.Data, 0);
            return(clone);
        }
Exemplo n.º 2
0
        public void Solve(IVector <double> f, double[] result)
        {
            //var e = DateTime.Now;
            SkylineMatrix2D <T> K = this;

            if (!K.isFactorized)
            {
                throw new InvalidOperationException("Cannot solve if matrix is not factorized.");
            }
            if (!(typeof(T) == typeof(double)))
            {
                throw new InvalidOperationException("Cannot solve for types other than double");
            }
            if (K.Rows != f.Length)
            {
                throw new InvalidOperationException("Matrix and vector size mismatch.");
            }
            double[] d = K.Data as double[];
            //double[] result = new double[K.Rows];
            f.CopyTo(result, 0);

            // RHS vector reduction
            int n;

            for (n = 0; n < K.Rows; n++)
            {
                int KL = K.RowIndex[n] + 1;
                int KU = K.RowIndex[n + 1] - 1;
                if (KU >= KL)
                {
                    int    k = n;
                    double C = 0;
                    for (int KK = KL; KK <= KU; KK++)
                    {
                        k--;
                        C += d[KK] * result[k];
                    }
                    result[n] -= C;
                }
            }

            // Back substitution
            for (n = 0; n < K.Rows; n++)
            {
                result[n] /= d[K.RowIndex[n]];
            }

            n = K.Rows - 1;
            for (int l = 1; l < K.Rows; l++)
            {
                int KL = K.RowIndex[n] + 1;
                int KU = K.RowIndex[n + 1] - 1;
                if (KU >= KL)
                {
                    int k = n;
                    for (int KK = KL; KK <= KU; KK++)
                    {
                        k--;
                        result[k] -= d[KK] * result[n];
                    }
                }
                n--;
            }
            //var x = new List<TimeSpan>();
            //x.Add(DateTime.Now - e);
        }