using System; using System.Collections.Generic; using System.Linq; using System.Text; using MathNet.Numerics.LinearAlgebra; namespace MatrixCalculator { static class MatrixHelper { public static bool Equal(Matrix a, Matrix b) { if (a.RowCount != b.RowCount || a.ColumnCount != b.ColumnCount) return false; for (int i = 0; i < a.RowCount; i++) for (int j = 0; j < a.ColumnCount; j++) if (a[i, j] != b[i, j]) return false; return true; } public static Matrix Power(Matrix mat, int power) { // Solution Matrix sol = Matrix.Build.DenseIdentity(mat.RowCount, mat.ColumnCount); if (power < 0) { mat = mat.Inverse(); power *= -1; } // Now raise to power binary for (int i = 0; (1 << i) <= power; i++) { if ((power & (1 << i)) != 0) sol = (sol * mat); mat = (mat * mat); } // Done return sol; } public static double Max(Matrix mat) { double max = double.MinValue; for (int i = 0; i < mat.RowCount; i++) for (int j = 0; j < mat.ColumnCount; j++) max = Math.Max(mat[i, j], max); return max; } public static double Min(Matrix mat) { double min = double.MaxValue; for (int i = 0; i < mat.RowCount; i++) for (int j = 0; j < mat.ColumnCount; j++) min = Math.Min(mat[i, j], min); return min; } } }