标题:求矩阵逆的好思路
只看楼主
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
结帖率:100%
 问题点数:0 回复次数:1 
求矩阵逆的好思路
Rev_Arr.rar (2.98 KB)

上面是我用VS2005做的求二三阶矩阵逆的dll,阶数高点的做不下去了!大家有什么好的思路来求矩阵的逆啊!
搜索更多相关主题的帖子: 矩阵 
2011-04-23 00:43
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
得分:0 
程序代码:
using System;
using System.Collections.Generic;
using System.Text;

namespace ArrRev
{
    public static class Arr_Rev//假如不存在逆矩阵,将数组清空为0。高手注意数组是引用,dll返回的是逆矩阵,原来的数据被覆盖了!为了简单起见,请先将矩阵从左到右,从上到下转换成一维的数组

    {
        private static double Mul_TWO(params double[] m) //二阶行列式的值
        {
            double Result = m[0] * m[3] - m[1] * m[2];
           
            return Result;
        }

        private static double Mul_THREE(params double[] m) //三阶行列式的值
        {
            double temp1 = m[0] * Mul_TWO(m[4], m[5], m[7], m[8]);
            double temp2 = m[1] * Mul_TWO(m[3], m[5], m[6], m[8]);
            double temp3 = m[2] * Mul_TWO(m[3], m[4], m[6], m[7]);

            double Result = temp1 + temp3 - temp2;

            return Result;
        }

        public static void Rev_TWO(double[] Arr) //求二维矩阵的逆
        {
            double Result = Arr[0] * Arr[3] - Arr[1] * Arr[2];
           
            if (Result != 0)
            {
                double Num1=Arr[0];
                double Num2=Arr[1];
                double Num3=Arr[2];
                double Num4=Arr[3];

           
                Arr[0] = Num4 / Result;
                Arr[1] = -Num2 / Result; //求伴随矩阵
                Arr[2] = -Num3 / Result;
                Arr[3] = Num1 / Result;
            }
            else
            {
                for (int i = 0; i < 4; i++)
                    Arr[i] = 0;
            }
        }

        public static void Rev_THREE(double[] Arr) //求三维矩阵的逆
         {
            double Result = Mul_Three(Arr);

            if (Result != 0)
            {
                double[] m = new double[9];

                m[0] = Mul_TWO(Arr[4], Arr[5], Arr[7], Arr[8]); //求伴随矩阵
                m[1] = -Mul_TWO(Arr[1], Arr[2], Arr[7], Arr[8]);
                m[2] = Mul_TWO(Arr[1], Arr[2], Arr[4], Arr[5]);
                m[3] = -Mul_TWO(Arr[3], Arr[5], Arr[6], Arr[8]);
                m[4] = Mul_TWO(Arr[0], Arr[2], Arr[6], Arr[8]);
                m[5] = -Mul_TWO(Arr[0], Arr[2], Arr[3], Arr[5]);
                m[6] = Mul_TWO(Arr[3], Arr[4], Arr[6], Arr[7]);
                m[7] = -Mul_TWO(Arr[0], Arr[1], Arr[6], Arr[7]);
                m[8] = Mul_TWO(Arr[0], Arr[1], Arr[3], Arr[4]);

                for (int i = 0; i < 9; i++)
                {
                    Arr[i] = m[i] / Result;
                }
            }
            else
            {
                for (int i = 0; i < 9; i++)
                {
                    Arr[i] = 0;
                }
            }
        }
    }
}


[ 本帖最后由 qq1023569223 于 2011-4-23 00:53 编辑 ]

   唯实惟新 至诚致志
2011-04-23 00:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-337626-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.122676 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved