MyMathLib系列(线性空间)
2015-01-07 20:40
281 查看
线性空间的算法不是特别多,这里是代码:
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; } } }
相关文章推荐
- MyMathLib系列(行列式计算3)
- MyMathLib系列(订正两个函数)
- MyMathLib系列(行列式计算)
- MyMathLib系列(向量及矩阵--准备工作)
- MyMathLib系列(一元多项式运算求初等因子等)
- MyMathLib系列(行列式计算4--向量部分)
- MyMathLib系列(一元多项式-准备)
- MyMathLib系列(行列式计算)
- MyMathLib系列(矩阵算法--2)
- MyMathLib系列(行列式计算2)
- MyMathLib系列(向量运算--1)
- MyMathLib系列(行列式计算2)
- 数学课堂 | 线性代数系列 -- 线性空间
- MyMathLib的全部源码已上传到CSDN
- Modern C#系列课程(2):类, 组和名称空间
- 《深入研究Windows内部原理系列课程》[ISO]http://lib.verycd.com/2007/04/12/0000146419.html
- 图解 Linux 内存管理 -- 线性空间与物理内存
- C/C++面试之算法系列--不申请变量和空间反转字符串
- [InnoDB系列] - InnoDB释放表空间
- Linux内存线性地址空间布局解析