Exemple #1
0
 internal static void SubFrom(ref MxMatrix from, MxMatrix subtractor, int dim)
 {
     for (var i = 0; i < dim * dim; i++)
     {
         from[i] -= subtractor[i];
     }
 }
Exemple #2
0
        internal bool Jacobi(MxMatrix input, ref double[] eigenValues, ref double[] eigenVectors)
        {
            var a = new[] { new double[3], new double[3], new double[3] };
            var v = new[] { new double[3], new double[3], new double[3] };

            for (var i = 0; i < 3; i++)
            {
                for (var j = 0; j < 3; j++)
                {
                    a[i][j] = input[i, j];
                }
            }

            var result = InternalJacobi(a, ref eigenValues, ref v);

            if (!result)
            {
                return(false);
            }

            var index = 0;

            for (var i = 0; i < 3; i++)
            {
                for (var j = 0; j < 3; j++)
                {
                    eigenVectors[index++] = v[j][i];
                }
            }

            return(true);
        }
Exemple #3
0
 internal static void AddInto(ref MxMatrix into, MxMatrix addend, int dim)
 {
     for (var i = 0; i < dim * dim; i++)
     {
         into[i] += addend[i];
     }
 }
Exemple #4
0
 internal static void Scale(ref MxMatrix mat, double scalar, int dim)
 {
     for (var i = 0; i < dim * dim; i++)
     {
         mat[i] *= scalar;
     }
 }
Exemple #5
0
        internal static void InvScale(ref MxMatrix mat, double scalar, int dim)
        {
            var invScale = 1.0 / scalar;

            for (var i = 0; i < dim * dim; i++)
            {
                mat[i] *= invScale;
            }
        }
Exemple #6
0
 internal MxMatrix(MxMatrix mat)
     : base(mat.Dim, mat.Dim)
 {
     Copy(mat);
 }
Exemple #7
0
        private static double InternalInvert(MxMatrix matA, ref MxMatrix matInvA)
        {
            var    dim = matA.Dim;
            int    i, j = 0, k;
            double max, t, det, pivot;

            //Initialize the inverse matrix as the Identity matrix
            for (i = 0; i < dim; i++)
            {
                for (j = 0; j < dim; j++)
                {
                    matInvA[i, j] = ((i == j) ? 1.0 : 0.0);
                }
            }

            det = 1.0;
            // eliminate in column i, below the diagonal
            for (i = 0; i < dim; i++)
            {
                max = -1.0;
                for (k = i; k < dim; k++)
                {
                    var abs = Math.Abs(matA[k, i]);
                    if (abs <= max)
                    {
                        continue;
                    }

                    max = abs;
                    j   = k;
                }

                if (max <= 0.0)
                {
                    return(0.0);
                }
                if (j != i)
                {
                    for (k = i; k < dim; k++)
                    {
                        t          = matA[i, k];
                        matA[i, k] = matA[j, k];
                        matA[j, k] = t;
                    }
                    for (k = 0; k < dim; k++)
                    {
                        t             = matInvA[i, k];
                        matInvA[i, k] = matInvA[j, k];
                        matInvA[j, k] = t;
                    }
                    det = -det;
                }

                pivot = matA[i, i];
                det  *= pivot;

                for (k = i + 1; k < dim; k++)
                {
                    matA[i, k] /= pivot;
                }
                for (k = 0; k < dim; k++)
                {
                    matInvA[i, k] /= pivot;
                }

                for (j = i + 1; j < dim; j++)
                {
                    t = matA[j, i];
                    for (k = i + 1; k < dim; k++)
                    {
                        matA[j, k] -= matA[i, k] * t;
                    }
                    for (k = 0; k < dim; k++)
                    {
                        matInvA[j, k] -= matInvA[i, k] * t;
                    }
                }
            }

            for (i = (dim - 1); i > 0; i--)
            {
                for (j = 0; j < i; j++)
                {
                    t = matA[j, i];
                    for (k = 0; k < dim; k++)
                    {
                        matInvA[j, k] -= matInvA[i, k] * t;
                    }
                }
            }

            return(det);
        }
Exemple #8
0
        internal static double Invert(MxMatrix matA, MxMatrix matInvA)
        {
            var a2 = new MxMatrix(matInvA);

            return(InternalInvert(matA, ref a2));
        }