MyMathLib系列(線性空間),mymathlib線性

來源:互聯網
上載者:User

MyMathLib系列(線性空間),mymathlib線性

線性空間的演算法不是特別多,這裡是代碼:

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace MyMathLib{    /// <summary>    /// 線性空間    /// </summary>    public class LinearSpace    {        /// <summary>        /// 求向量Vector在基底BasisOfLinearSpace下的座標向量        /// </summary>        /// <param name="BasisOfLinearSpace">線性空間的基</param>        /// <param name="Vector">目標向量</param>        /// <returns>座標向量.</returns>        public static double[] CalcVectorCoordinate(List<double[]> BasisOfLinearSpace,double[] Vector)        {            if (BasisOfLinearSpace == null && BasisOfLinearSpace.Count <= 0)            {                throw new Exception("基底不可為空!");            }            var theCoeffs = BasisOfLinearSpace.To2DArrayT();            var theRet = LinearAlgebra.LinearEquationsEM2(theCoeffs, Vector);            if (theRet.SolutionType == SolutionType.OnlyOne)            {                return theRet.SolutionVectors[0];            }            throw new Exception("參數錯誤!");        }        /// <summary>        /// 求向量Vector在另一個基底下的座標向量        /// </summary>        /// <param name="P">過渡矩陣</param>        /// <param name="Vector">向量</param>        /// <returns>座標向量.</returns>        public static double[] CalcVectorY(double[,] P, double[] Vector)        {            if (P == null || P.GetLength(0) <= 0 || P.GetLength(1) <= 0)            {                throw new Exception("過渡矩陣不可為空!");            }            var theP = new TMatrix(P);            var theP1 = TMatrix.GetInverseMatrix(theP);            double[][] theVectors = new double[1][];            theVectors[0] = Vector;            var theAt = TMatrix.Transposition(new TMatrix(theVectors));            var theRet = (theP1 * theAt);            return theRet.Elements.GetVectorCol(0);        }        /// <summary>        /// 擷取T在此基底下的座標矩陣A.        /// </summary>        /// <param name="P">變換矩陣</param>        /// <param name="BasisVectors">基底</param>        /// <returns>座標矩陣A</returns>        public static TMatrix CalcCoordinateMatrixOfT(double[,] P, List<double[]> BasisVectors)        {            if (BasisVectors ==null || P == null ||                 P.GetLength(0) <= 0 || P.GetLength(1) <= 0                || P.GetLength(0)!=P.GetLength(1)                || P.GetLength(0)!=BasisVectors.Count                || BasisVectors.Count <=0                 || BasisVectors[0].Length != BasisVectors.Count)            {                throw new Exception("參數有誤!");            }            var theBasis = BasisVectors.To2DArrayT();            var theBasisM =  new TMatrix(theBasis);            var thePM =  new TMatrix(P);            var theBasisM_1 = TMatrix.GetInverseMatrix(theBasisM);            return theBasisM_1 * thePM * theBasisM;        }        /// <summary>        /// 擷取T在此BasisVectors基底下的關係矩陣P.        /// </summary>        /// <param name="A">T在基底下的座標矩陣A</param>        /// <param name="BasisVectors">基底矩陣</param>        /// <returns>座標矩陣A</returns>        public static TMatrix CalcRelationMatrixOfT(double[,] A, List<double[]> BasisVectors)        {            if (BasisVectors == null || A == null ||                A.GetLength(0) <= 0 || A.GetLength(1) <= 0                || A.GetLength(0) != A.GetLength(1)                || A.GetLength(0) != BasisVectors.Count                || BasisVectors.Count <= 0                || BasisVectors[0].Length != BasisVectors.Count)            {                throw new Exception("參數有誤!");            }            var theBasis = BasisVectors.To2DArrayT();            var theBasisM = new TMatrix(theBasis);            var thePM = new TMatrix(A);            var theBasisM_1 = TMatrix.GetInverseMatrix(theBasisM);            return theBasisM  * thePM * theBasisM_1;        }    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.