/// <summary>
        /// 計算Tsquare
        /// </summary>
        /// <param name="item">a observation</param>
        /// <param name="mean">mean vector</param>
        /// <param name="invS">inverse of covariance matrix</param>
        /// <returns></returns>
        public static double CalculateTSquare(LinearAlgebra.Matrix <double> item, LinearAlgebra.Matrix <double> mean, LinearAlgebra.Matrix <double> invS)
        {
            if (item.ColumnCount != mean.ColumnCount || item.ColumnCount != invS.ColumnCount || mean.ColumnCount != invS.ColumnCount)
            {
                throw new ArgumentException("矩陣的維度無法計算");
            }

            LinearAlgebra.Matrix <double> diff = item - mean;
            var t2 = diff.Multiply(invS).Multiply(diff.Transpose());

            return(t2.At(0, 0));
        }
示例#2
0
        public LinearAlgebra.Matrix <double> ComputeStiffnessMatrix()
        {
            LinearAlgebra.Matrix <double> K = LinearAlgebra.Matrix <double> .Build.Dense(2, 2);

            double x1 = Nodes[0].Point.X;
            double y1 = Nodes[0].Point.Y;
            double z1 = Nodes[0].Point.Z;

            double x2 = Nodes[1].Point.X;
            double y2 = Nodes[1].Point.Y;
            double z2 = Nodes[1].Point.Z;

            ElemLength = Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1));

            K[0, 0] = Area * StiffnessModulus / ElemLength;
            K[0, 1] = -Area * StiffnessModulus / ElemLength;
            K[1, 0] = -Area * StiffnessModulus / ElemLength;
            K[1, 1] = Area * StiffnessModulus / ElemLength;

            // Tranform to global element stiffness matrix using transformation matrix G

            double nxx = (x2 - x1) / ElemLength;
            double nyx = (y2 - y1) / ElemLength;
            double nzx = (z2 - z1) / ElemLength;

            G[0, 0] = nxx;
            G[0, 1] = nyx;
            G[0, 2] = nzx;
            G[1, 3] = nxx;
            G[1, 4] = nyx;
            G[1, 5] = nzx;


            LinearAlgebra.Matrix <double> GT      = G.Transpose();
            LinearAlgebra.Matrix <double> KGlobal = (GT.Multiply(K)).Multiply(G);

            return(KGlobal);
        }