C#的矩阵类

这篇博客介绍了为课程设计而编写的C#矩阵类,该类支持基本的矩阵操作,是C#编程中数学计算的一个实用工具。
摘要由CSDN通过智能技术生成

因为课程设计的需要,写的C#矩阵类,可以实现基本的矩阵操作。

_Matrix类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Matrix_Mul
{
    public class _Matrix
    {
        public int m;
        public int n;
        public double[] arr;

        //初始化    
        public _Matrix()
        {
            m = 0;
            n = 0;
        }

        public _Matrix(_Matrix s)
        {
            this.m = s.m;
            this.n = s.n;
            arr = new double[m * n];
            for (int i = 0; i < m * n; i++)
            {
                this.arr[i] = s.arr[i];
            }
        }

        public _Matrix(int mm, int nn)
        {
            m = mm;
            n = nn;
        }

        //设置m    
        public void set_mn(int mm, int nn)
        {
            m = mm;
            n = nn;
        }


        //设置m    
        public void set_m(int mm)
        {
            m = mm;
        }

        //设置n    
        public void set_n(int nn)
        {
            n = nn;
        }

        //初始化    
        public void init_matrix()
        {
            arr = new double[m * n];
        }

        //释放    
        public void free_matrix()
        {
            //delete [] arr;  
        }

        //读取i,j坐标的数据    
        //失败返回-31415,成功返回值    
        public double read(int i, int j)
        {
            if (i >= m || j >= n)
            {
                return -31415;
            }

            //return *(arr + i * n + j);  
            return arr[i * n + j];
        }

        //写入i,j坐标的数据    
        //失败返回-1,成功返回1    
        public int write(int i, int j, double val)
        {
            if (i >= m || j >= n)
            {
                return -1;
            }

            arr[i * n + j] = val;
            return 1;
        }
        public double sums()
        {
            double a = 0;
            for (int i = 0; i < this.m; i++)
            {
                for (int j = 0; j < this.n; j++)
                {
                    a += this.read(i, j);
                }
            }
            return a;
        }


    };
}

_Matrix_Calc类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Matrix_Mul
{
    public class _Matrix_Calc
    {
        //初始化  
        public _Matrix_Calc()
        {

        }

       

        /// <summary>
        /// C=A+B
        /// </summary>
        /// <param name=
  • 4
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值