MyMathLib系列(行列式计算2)

/// <summary>
    /// 行列式计算,本程序属于MyMathLib的一部分,欢迎使用,参考,提意见。
    /// 有时间用函数语言改写,做自己得MathLib,里面的算法经过验证,但没经过
    /// 严格测试,如需参考,请慎重.
    /// </summary>
    public static partial class LinearAlgebra
    { /// <summary>
        /// 获取指定i,j的余子式
        /// </summary>
        /// <param name="Determinants">N阶行列式</param>
        /// <param name="i">第i行</param>
        /// <param name="j">第j列</param>
        /// <returns>计算结果</returns>
        public static T[,] GetDeterminantMij<T>(T[,] Determinants, int i, int j)
        {
            var theN = Determinants.GetLength(0);
            var theNewDeter = new T[theN - 1, theN - 1];
            int theI = -1;

            for (int k = 0; k < theN; k++)
            {
                if (k == i - 1)
                {
                    continue;
                }
                theI++;
                int theJ = -1;
                for (int l = 0; l < theN; l++)
                {
                    if (l == j - 1)
                    {
                        continue;
                    }
                    theJ++;
                    theNewDeter[theI, theJ] = Determinants[k, l];
                }
            }
            return theNewDeter;
        }
        /// <summary>
        /// 获取指定i,j的余子式
        /// </summary>
        /// <param name="Determinants">N阶行列式</param>
        /// <param name="Rows">要取得行</param>
        /// <param name="Cols">要取得列</param>
        /// <returns>计算结果</returns>
        public static T[,] GetDeterminantMij<T>(T[,] Determinants, int[] Rows, int[] Cols)
        {
            if (Rows.Length != Cols.Length)
            {
                throw new Exception("所取行数和列数必须相等!");
            }
            var theN = Determinants.GetLength(0);
            var theNewN = theN - Rows.Length;
            var theNewDeter = new T[theNewN, theNewN];
            int theI = -1;

            for (int k = 0; k < theN; k++)
            {
                if (Rows.Contains(k + 1))
                {
                    continue;
                }
                theI++;
                int theJ = -1;
                for (int l = 0; l < theN; l++)
                {
                    if (Cols.Contains(l + 1))
                    {
                        continue;
                    }
                    theJ++;
                    theNewDeter[theI, theJ] = Determinants[k, l];
                }
            }
            return theNewDeter;
        }
        /// <summary>
        /// 获取指定k阶子式N
        /// </summary>
        /// <para
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值