Summary
This paper introduces the programming representation of Matrix, elementary transformation of matrix, the step matrix and the determinant of square.
Matrix Introduction
The matrix is an MXN plane table, with a two-D array can be expressed, for the convenience of input, we use a special format of the string to initialize the matrix, with "|" Split each row, "," split each column, and add a show method to print out the matrix, in order to test and debug the need to rewrite the ToString () method.
Code
public class Matrix {
public int M {get; private set;}
public int N {get; private set;}
Private readonly double[,] num = null;
#region Constructor/show
Public Matrix (int m, int n, string input) {
m = m;
n = n;
num = new double[m, n];
if (!string. IsNullOrEmpty (input))
Parseinput (input);
}
private void Parseinput (string input) {
string[] rows = input. Split (new[] {' | '});
If rows. Length!= M)
throw new ArgumentException ("Row count err");
for (int i = 0; i < M; i++) {
String row = Rows[i];
String[] cells = row. Split (new[] {', '});
if (cells. Length!= N)
throw new ArgumentException (string. Format ("Cells Counte err:{0}", row));
for (int j = 0; J < N; J + +) {
int cellvalue;
if (!int. TryParse (Cells[j], out Cellvalue))
throw new ArgumentException (string. Format ("Cell error:{0}", Cells[j]);
Num[i, j] = Cellvalue;
}
}
}
public void Show () {
for (int i = 0; i < M; i++) {
for (int j = 0; J < N; + +)
Console.Write ("{0}\t", Num[i, j]);
Console.WriteLine ();
}
}
public override string ToString () {
StringBuilder sb = new StringBuilder ();
for (int i = 0; i < M; i++) {
for (int j = 0; J < N; J + +) {
Sb. Append (Num[i, j]);
if (J!= N-1)
Sb. Append (', ');
}
if (i!= M-1)
Sb. Append (' | ');
}
Return SB. ToString ();
}
}