C 下的矩陣演算法類

2021-06-28 15:32:13 字數 3766 閱讀 1855

using system;

using system.collections.generic;

using system.text;

namespace mymath.matrix

set

}public int row

//set

}private int column;

public int column

//set

}/// /// 構造方陣

///

///

public matrix(int row)

else

}/// /// 構造矩陣

///

///

public matrix(int row, int column)

else

}/// /// 複製矩陣

///

/// 要複製的矩陣

public matrix(matrix m)}}

/// /// 獲取和設定某行某列的值

///

/// 行

/// 列

/// 對應的值

public double this[int row, int column]

set}

/// /// 將該矩陣設定為單位陣

///

public void setunit()

else}}

}else

}/// /// 矩陣初等變換,調換兩行的值

///

///

///

public matrix rowexchange(int row1, int row2)

return this;

}else

}/// /// 矩陣初等變換,調換兩列的值

///

///

///

//public matrix rowexchange(int column1, int column2)

//// return this;

// }

// else

//

//}/// /// 矩陣初等變換,將第row行乘以mul

///

/// 行數

/// 乘數

///

public matrix rowmultiple(int row, double mul)

return this;

}else

}/// /// 矩陣初等變換,將第row2行資料乘以mul加到第row1行

///

///

///

///

///

public matrix multipleadd(int row1, int row2, double mul)

return this;

}else

}/// /// 求當前矩陣的轉置矩陣

///

///

public matrix transpose()

}return transposematrix;

}/// /// 操作符過載 +

///

///

///

///

public static matrix operator +(matrix m1, matrix m2)

matrix resultmatrix = new matrix(m1.row, m1.column);

for (int i = 0; i < m1.row; i++)

}return resultmatrix;

}/// /// 操作符過載 -

///

///

///

///

public static matrix operator -(matrix m1, matrix m2)

matrix resultmatrix = new matrix(m1.row, m1.column);

for (int i = 0; i < m1.row; i++)

}return resultmatrix;

}/// /// 操作符過載,兩個矩陣相乘

///

///

///

///

public static matrix operator *(matrix m1, matrix m2)

matrix resultmatrix = new matrix(m1.row, m2.column);

for (int i = 0; i < m1.row; i++)

catch

"i-------->"+i+" j------>"+j+" k------->"+k);

}"j-------->"+j);

}"i----------->"+i);

}return resultmatrix;

}/// /// 操作符過載,常數乘以矩陣

///

///

///

///

public static matrix operator *(double mul, matrix m)

}return resultmatrix;

}/// /// 操作符過載 /,矩陣除以常數

///

///

///

///

public static matrix operator /(matrix m, double div)

}return resultmatrix;

}/// /// 操作符過載,乙個數除以矩陣等於乘以矩陣的逆矩陣

///

///

///

///

public static matrix operator /(double div, matrix m)

/// /// 查詢矩陣的列主元

///

/// 開始查詢的行數

/// 要尋找列主元的列數

///

public int columnpivot(int startrow, int serchcolumn)

}return indextemp;

}/// /// 計算矩陣的模

///

///

public double cculatemodule()

/// /// 矩陣的代數余子式矩陣

///

///

public matrix algebraiccomplementminormatrix()

}return resultmatrix;

}/// /// 計算矩陣的逆

///

///

public matrix inverse()

/// /// 判斷是否是對稱矩陣

///

///

public bool ismirror()

for (int i = 0; i < this.row; i++)}}

return true;

}/// /// 覆寫字串函式

///

///

public override string tostring()

s += "\n";

}return s;}}

}

CMatrix類 矩陣類 C

pragma once class matrix 返回行 intcol const 返回列 void setsize int row,int col 調整陣列的大小,原有資料不變 未測試 double operator int row,int col 獲取矩陣元素 double operator i...

基於C 的矩陣類

這個矩陣類雖然小,但有專門的官網,很適合用小型專案。特別是,它完全過載了所有矩陣的運算子,矩陣的加減乘法,轉置,求逆等等,都實現得非常好。例如下邊這個官網的例項 問題 設定乙個二維陣列 double a new double 4,4 double c new double 4,1 用二維陣列構建乙個...

c 變幻的矩陣 矩陣類 實現矩陣的基本變換

矩陣類 class matrix 根據行 列返回矩陣元素 getitem r,c 根據行 列設定矩陣元素 setitem r,c,item 換行 swaprow r1,r2 按行遍歷矩陣元素,返回元素item,行r,列c roweach callback 按豎遍歷矩陣元素,返回元素item,行r,列...