/* * Special matrix */ /// <summary> /// Return a vandermonde matrix /// </summary> /// <param name="n"></param> /// <returns></returns> public static Matrix Vandermonde(int n) { Matrix vandermonde = new Matrix(n + 1, n + 1); for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { vandermonde.set(i, j, Math.Pow(i, j)); } } return(vandermonde); }
public static Matrix Transpose(Matrix a) { Matrix result = new Matrix(a.Width(), a.Height()); for (int i = 0; i < a.Height(); i++) { for (int j = 0; j < a.Width(); j++) { result.set(j, i, a.get(i, j)); } } return(result); }
public static Matrix Map(Matrix m, Func <double, double> func) { Matrix result = new Matrix(m.Height(), m.Width()); for (int i = 0; i < m.Height(); i++) { for (int j = 0; j < m.Width(); j++) { result.set(i, j, func(m.get(i, j))); } } return(result); }
/* * Static function */ public static Matrix Randomized(int l, int c, int rStart, int rEnd) { Matrix m = new Matrix(l, c); for (int i = 0; i < m.Height(); i++) { for (int j = 0; j < m.Width(); j++) { m.set(i, j, random.Next(rStart, rEnd)); } } return(m); }
public static Matrix Sub(Matrix a, Matrix b) { if (a.Width() != b.Width() || a.Height() != b.Height()) { throw new MatrixException("Dimension not egual"); } Matrix m = new Matrix(a.Height(), a.Width()); for (int l = 0; l < a.Height(); l++) { for (int c = 0; c < a.Width(); c++) { m.set(l, c, a.get(l, c) - b.get(l, c)); } } return(m); }
public static Matrix Mult(Matrix a, Matrix b) { if (a.Width() != b.Height()) { throw new MatrixException("Width is not egual to the Height (" + a.Width() + ", " + b.Height() + ")"); } Matrix tmp = new Matrix(a.Height(), b.Width()); for (int l = 0; l < tmp.Height(); l++) { for (int c = 0; c < tmp.Width(); c++) { for (int k = 0; k < b.Height(); k++) { tmp.set(l, c, tmp.get(l, c) + a.get(l, k) * b.get(k, c)); } } } return(tmp); }