internal ComplexVector(ComplexMatrix inner) { if (inner.Columns != 1) { throw new ArgumentException(); } this.inner = inner; }
public ComplexVector(Complex[] entries) { int n = entries.Length; Complex[,] a = new Complex[n, 1]; for (int i = 0; i < n; i++) { a[i, 0] = entries[i]; } inner = new ComplexMatrix(a); }
public ComplexMatrix SetMatrix(int row, int column, ComplexMatrix a) { if (row < 0 || row + a.rows > rows || column < 0 || column + a.columns > columns) { throw new IndexOutOfRangeException(); } ComplexMatrix b = new ComplexMatrix(rows, columns, entries); for (int i = 0; i < a.rows; i++) { for (int j = 0; j < a.columns; j++) { b.SetEntryInternal(row + i, column + j, a.GetEntryInternal(i, j)); } } return b; }
public ComplexMatrix SetEntry(int row, int column, Complex t) { if (row < 0 || row >= rows || column < 0 || column >= columns) { throw new IndexOutOfRangeException(); } ComplexMatrix a = new ComplexMatrix(rows, columns, entries); a.SetEntryInternal(row, column, t); return a; }
public ComplexMatrix GetMatrix(int row, int column, int rows, int columns) { if (row < 0 || row + rows > this.rows || column < 0 || column + columns > this.columns) { throw new IndexOutOfRangeException(); } int n = rows; int m = columns; ComplexMatrix a = new ComplexMatrix(n, m); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { a.SetEntryInternal(i, j, GetEntryInternal(row + i, column + j)); } } return a; }
public static ComplexMatrix Transpose(ComplexMatrix a) { int n = a.columns; int m = a.rows; ComplexMatrix b = new ComplexMatrix(n, m); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { b.SetEntryInternal(i, j, a.GetEntryInternal(j, i)); } } return b; }
public static Complex Trace(ComplexMatrix a) { int n = Math.Min(a.rows, a.columns); Complex s = 0.0; for (int i = 0; i < n; i++) { s += a[i, i]; } return s; }
public static ComplexMatrix Identity(int rows, int columns) { int n = Math.Min(rows, columns); ComplexMatrix a = new ComplexMatrix(rows, columns); for (int i = 0; i < n; i++) { a.SetEntryInternal(i, i, 1.0); } return a; }
public static ComplexMatrix Diagonal(Complex[] values) { int n = values.Length; ComplexMatrix a = new ComplexMatrix(n, n); for (int i = 0; i < n; i++) { a.SetEntryInternal(i, i, values[i]); } return a; }
public static ComplexMatrix Basis(int rows, int columns, int row, int column) { if (row < 0 || row >= rows || column < 0 || column >= columns) { throw new IndexOutOfRangeException(); } ComplexMatrix a = new ComplexMatrix(rows, columns); a.SetEntryInternal(row, column, 1.0); return a; }
public static ComplexMatrix operator -(Complex t, ComplexMatrix a) { int n = a.rows; int m = a.columns; ComplexMatrix b = new ComplexMatrix(n, m); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { b.SetEntryInternal(i, j, t - a.GetEntryInternal(i, j)); } } return b; }
public static ComplexMatrix operator -(ComplexMatrix a, ComplexMatrix b) { int n = a.rows; int m = a.columns; if (b.rows != n || b.columns != m) { throw new ArgumentException("The matrix dimensions don't match."); } ComplexMatrix c = new ComplexMatrix(n, m); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { c.SetEntryInternal(i, j, a.GetEntryInternal(i, j) - b.GetEntryInternal(i, j)); } } return c; }
public static ComplexMatrix operator +(ComplexMatrix a, Complex t) { int n = a.Rows; int m = a.Columns; ComplexMatrix c = new ComplexMatrix(n, m); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { c.SetEntryInternal(i, j, a.GetEntryInternal(i, j) + t); } } return c; }
public static ComplexMatrix operator *(ComplexMatrix a, ComplexMatrix b) { int n = a.rows; int m = b.columns; int l = a.columns; if (b.rows != l) { throw new ArgumentException("The matrix dimensions don't match."); } ComplexMatrix c = new ComplexMatrix(n, m); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { Complex s = 0.0; for (int k = 0; k < l; k++) { s += a.GetEntryInternal(i, k) * b.GetEntryInternal(k, j); } c.SetEntryInternal(i, j, s); } } return c; }