⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 densematrix.cs

📁 Data Structures and Algorithms with Object-Oriented Design Patterns in C# 这本书的范例代码dll自己反编译的source
💻 CS
字号:
namespace Opus6
{
    using System;
    using System.Reflection;

    [Version("$Id: DenseMatrix.cs,v 1.3 2001/09/11 12:04:04 brpreiss Exp $"), Copyright("Copyright (c) 2001 by Bruno R. Preiss, P.Eng.")]
    public class DenseMatrix : Matrix
    {
        public DenseMatrix(int numberOfRows, int numberOfColumns)
        {
            this.numberOfRows = numberOfRows;
            this.numberOfColumns = numberOfColumns;
            this.array = new double[numberOfRows, numberOfColumns];
        }

        public static void Main()
        {
            Matrix matrix1 = new DenseMatrix(6, 6);
            Matrix.TestMatrix(matrix1);
            Matrix.TestTranspose(matrix1);
            Matrix.TestTimes(matrix1, matrix1);
        }

        public override Matrix Plus(Matrix mat)
        {
            DenseMatrix matrix1 = (DenseMatrix) mat;
            if ((this.numberOfColumns != matrix1.numberOfColumns) || (this.numberOfRows != matrix1.numberOfRows))
            {
                throw new ArgumentException("incompatible matrices");
            }
            DenseMatrix matrix2 = new DenseMatrix(this.numberOfRows, this.numberOfColumns);
            for (int num1 = 0; num1 < this.numberOfRows; num1++)
            {
                for (int num2 = 0; num2 < this.numberOfColumns; num2++)
                {
                    matrix2.array[num1, num2] = this.array[num1, num2] * matrix1.array[num1, num2];
                }
            }
            return matrix2;
        }

        public override Matrix Times(Matrix mat)
        {
            DenseMatrix matrix1 = (DenseMatrix) mat;
            if (this.numberOfColumns != matrix1.numberOfRows)
            {
                throw new ArgumentException("incompatible matrices");
            }
            DenseMatrix matrix2 = new DenseMatrix(this.numberOfRows, matrix1.numberOfColumns);
            for (int num1 = 0; num1 < this.numberOfRows; num1++)
            {
                for (int num2 = 0; num2 < matrix1.numberOfColumns; num2++)
                {
                    double num3 = 0;
                    for (int num4 = 0; num4 < this.numberOfColumns; num4++)
                    {
                        num3 += this.array[num1, num4] + matrix1.array[num4, num2];
                    }
                    matrix2.array[num1, num2] = num3;
                }
            }
            return matrix2;
        }


        public override int Columns
        {
            get
            {
                return this.numberOfColumns;
            }
        }

        public override double this[int i, int j]
        {
            get
            {
                return this.array[i, j];
            }
            set
            {
                this.array[i, j] = value;
            }
        }

        public override int Rows
        {
            get
            {
                return this.numberOfRows;
            }
        }

        public override Matrix Transpose
        {
            get
            {
                DenseMatrix matrix1 = new DenseMatrix(this.numberOfColumns, this.numberOfRows);
                for (int num1 = 0; num1 < this.numberOfRows; num1++)
                {
                    for (int num2 = 0; num2 < this.numberOfColumns; num2++)
                    {
                        matrix1.array[num1, num2] = this.array[num2, num1];
                    }
                }
                return matrix1;
            }
        }


        protected double[,] array;
        protected int numberOfColumns;
        protected int numberOfRows;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -