矩阵基本操作的实现(C# 源代码)

 

矩阵基本操作的实现(C# 源代码)

  1 using System;
  2using System.IO;
  3using System.Diagnostics;
  4
  5
  6namespace Adjust
  7{
  8    /// <summary>
  9    /// Matrix 的摘要说明。
 10    /// 实现矩阵的基本运算
 11    /// </summary>

 12    public class Matrix
 13    {
 14    
 15        //构造方阵
 16        public  Matrix(int row)
 17        {
 18            m_data = new double[row,row];
 19
 20        }

 21        public Matrix(int row,int col)
 22        {
 23            m_data = new double[row,col];
 24        }

 25        //复制构造函数
 26        public Matrix(Matrix m)
 27        {
 28            int row = m.Row;
 29            int col = m.Col;
 30            m_data = new double[row,col];
 31
 32            for(int i=0;i<row;i++)
 33                for(int j=0;j<col;j++)
 34                    m_data[i,j] = m[i,j];
 35
 36        }

 37
 38        /*
 39        //分配方阵的大小
 40        //对于已含有内存的矩阵,将清空数据
 41        public void SetSize(int row)
 42        {
 43            m_data = new double[row,row];
 44        }
 45
 46        
 47        //分配矩阵的大小
 48        //对于已含有内存的矩阵,将清空数据
 49        public void SetSize(int row,int col)
 50        {
 51            m_data = new double[row,col];
 52        }
 53        */

 54
 55        //unit matrix:设为单位阵
 56        public void SetUnit()
 57        {
 58            for(int i=0;i<m_data.GetLength(0);i++)
 59                for(int j=0;j<m_data.GetLength(1);j++)
 60                    m_data[i,j] = ((i==j)?1:0);
 61        }

 62
 63        //设置元素值
 64        public void SetValue(double d)
 65        {
 66            for(int i=0;i<m_data.GetLength(0);i++)
 67                for(int j=0;j<m_data.GetLength(1);j++)
 68                    m_data[i,j] = d;
 69        }

 70
 71        // Value extraction:返中行数
 72        public int Row
 73        {
 74            get
 75            {
 76
 77                return m_data.GetLength(0);
 78            }

 79        }

 80
 81        //返回列数
 82        public int Col
 83        {
 84            get
 85            {
 86                return m_data.GetLength(1);
 87            }

 88        }

 89
 90        //重载索引
 91        //存取数据成员
 92        public double this[int row,int col]
 93        {
 94            get
 95            {
 96                return m_data[row,col];
 97            }

 98            set
 99
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值