private void Button10_Click(Object sender, EventArgs e) { try { if (comboBox12.Text == Resources.res14) { var matrix = new Determinant <int>(Matrix <int> .GetLeftMatrix()); var determinant = matrix.Calculate(); MessageBox.Show(Resources.res13 + determinant.ToString() + '.', "Determinant"); } else { var matrix = new Determinant <double>(Matrix <double> .GetLeftMatrix()); var determinant = matrix.Calculate(); MessageBox.Show(Resources.res13 + determinant.ToString() + '.', "Determinant"); } } catch (NullReferenceException) { MessageBox.Show(Resources.res12, Resources.res03); } catch (MatrixLib.MatrixException exception) { MessageBox.Show(exception.Message, Resources.res03); } }
static void FunctionsDemo() { Console.WriteLine("Functions Demo"); try { int[,] array = { { 4, 1, 2, 3 }, { 4, 4, 5, 6 }, { 1, 7, 8, 9 } }; int[,] array2 = { { 1, 3, 4 }, { 4, 3, 1 }, { 0, 3, 0 }, { 3, 3, 3 } }; MyMatrix matrix1 = new MyMatrix(array); MyMatrix matrix2 = new MyMatrix(array2); MyMatrix matrix3 = matrix1 * matrix2; matrix3 *= 10; Console.WriteLine("Matrix 3 transposed"); PrintMatrix(matrix3.Transpose()); Console.WriteLine("Submatrix 2x2 of matrix 3"); PrintMatrix(matrix3.GetSubMatrix(2, 2)); Console.WriteLine($"Determinant of the subMatrix = {Determinant.GetDeterminant(matrix3.GetSubMatrix(2,2), matrix3.GetSubMatrix(2, 2).Rows)}"); } catch (Exception e) { throw e; } Console.WriteLine(new string('-', 30)); }
public void ExecuteEmptyMatrixTest() { var matrix = new Matrix(2, 2); var det = new Determinant(matrix); Assert.Throws <ArgumentException>(() => det.Execute()); }
public void ExecuteVectorTest() { var vector = new Vector(new[] { new Number(1), new Number(-2), new Number(3) }); var det = new Determinant(vector); Assert.Throws <ResultIsNotSupportedException>(() => det.Execute()); }
public void Determinant2x2tests() { var matrix = new double[2, 2]; var x = matrix.Rank; var y = matrix.Length; var z = matrix.SyncRoot; var a = matrix.IsFixedSize; var det = Determinant.Determinant2x2(matrix); }
public void Test1() { var determinant = new Determinant(new double[, ] { { 2, 3 }, { 7, 8 }, }); Assert.Equal(-5, determinant.Value); }
public void DeteminantOnesMatrix() { var a = Matrix <int> .CreateOnesMatrix(3, 3); var matr = new Determinant <int>(a); var detem = matr.Calculate(); Assert.AreEqual(1, detem); }
public void Test2() { var determinant = new Determinant(new double[, ] { { 2, 3, 4 }, { 3, 4, 5 }, { 6, 7, 8 }, }); Assert.Equal(0, determinant.Value); }
public void DeteminantException() { var matrOfArray = new double[, ] { { 0, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 7, 8, 9 } }; var a = new Matrix <double>(4, 3, matrOfArray); var dm = new Determinant <double>(a); Assert.ThrowsException <MatrixException>(() => dm.Calculate()); }
public void Test_Determinant() { Determinant d = new Determinant(); string[] array = { "1", "4", "3", "<>", "2", "3", "0", "<>", "5", "-3", "4" }; Console.WriteLine("Matrix Determinant:"); PrintArray(array, array.Length); Console.WriteLine("Output: {0}", d.MatrixDeterminant(array, array.Length)); Console.WriteLine(); }
public void DeterminantToStringTest() { var matrix = new Matrix(new[] { new Maths.Expressions.Matrices.Vector(new[] { new Number(1), new Number(-2) }), new Maths.Expressions.Matrices.Vector(new[] { new Number(4), new Number(0) }) }); var det = new Determinant(matrix); Assert.Equal("det({{1, -2}, {4, 0}})", det.ToString(commoonFormatter)); }
public void ExecuteIsNotSquareTest() { var matrix = new Matrix(new[] { new Vector(new[] { new Number(1), new Number(-2), new Number(3) }), new Vector(new[] { new Number(4), new Number(0), new Number(6) }) }); var det = new Determinant(matrix); Assert.Throws <ArgumentException>(() => det.Execute()); }
public void DeteminantUsersMatrixNumb() { var matrOfArray = new int[, ] { { 0, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; var a = new Matrix <int>(3, 3, matrOfArray); var matr = new Determinant <int>(a); var detem = matr.Calculate(); Assert.AreEqual(3, detem); }
public void ExecuteTest() { var matrix = new Matrix(new[] { new Vector(new[] { new Number(1), new Number(-2), new Number(3) }), new Vector(new[] { new Number(4), new Number(0), new Number(6) }), new Vector(new[] { new Number(-7), new Number(8), new Number(9) }) }); var det = new Determinant(matrix); Assert.Equal(204.0, det.Execute()); }
public void DeteminantUsersMatrix0() { var matrOfArray = new double[, ] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; var a = new Matrix <double>(3, 3, matrOfArray); var matr = new Determinant <double>(a); var detem = matr.Calculate(); Assert.AreEqual(0, detem); }
// Automatically generated public override int GetHashCode() { int hashCode = -1902641761; hashCode = hashCode * -1521134295 + Hand.GetHashCode(); hashCode = hashCode * -1521134295 + Determinant.GetHashCode(); hashCode = hashCode * -1521134295 + SubDeterminant.GetHashCode(); hashCode = hashCode * -1521134295 + Kicker.GetHashCode(); hashCode = hashCode * -1521134295 + SecondKicker.GetHashCode(); hashCode = hashCode * -1521134295 + ThirdKicker.GetHashCode(); hashCode = hashCode * -1521134295 + FourthKicker.GetHashCode(); return(hashCode); }
public void TestDeterminantsException2() { var exp = new Determinant( new Vector(new IExpression[] { new Number(3), new Number(7), new Number(2), new Number(5) })); TestException(exp); }
public void solve() { Matrix <CustomType <T> > matrixA = getMatrixA(); Matrix <CustomType <T> > matrixB = getMatrixB(); Matrix <CustomType <T> > invertedA = invertMatrix(matrixA); Matrix <CustomType <T> > adjunctMatrixA = adjunctMatrix(invertedA); Matrix <CustomType <T> > determinantOfA = new Determinant(matrixA).getValue(); Matrix <CustomType <T> > matrixX = getMatrixX(determinantOfA, adjunctMatrixA, matrixB); this.result = matrixX; }
private CompoundNumber[,] adjunctMatrix(CompoundNumber[,] matrix) { CompoundNumber[,] adjunctMatrix = new CompoundNumber[matrix.GetUpperBound(0) + 1, matrix.GetUpperBound(1) + 1]; for (int i = 0; i <= adjunctMatrix.GetUpperBound(0); i++) { for (int j = 0; j <= adjunctMatrix.GetUpperBound(0); j++) { adjunctMatrix[i, j] = new Determinant(matrix, i, j).getValue(); } } return(adjunctMatrix); }
public void GetSetDeterminantMatrixDouble() { var a = Matrix <double> .CreateZeroMatrix(4, 5); var matrA = new double[, ] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 10, 11, 12 } }; var c = new Matrix <double>(4, 3, matrA); var sm = new Determinant <double>(a); sm.MatrixOperand = c; Assert.AreEqual(sm.MatrixOperand, c); }
//private static object a; //NB:"Most of my comments was me trying other solutions before arriving at this one. I just thought to leave my rough journey on the console" static void Main(string[] args) { try { DataStructures(); Determinant sqr = 0; Console.ReadLine(); } catch (Exception) { throw; } }
//private static void DataStructures() //{ // throw new NotImplementedException(); //} //nrow = 0; public static void DataStructures() { Console.WriteLine("Welcome to my program which calculates the determinant of the 4D array below\n"); //The matrix has 2 number of rows and 3 columns int i,j; int[,,,] my4Darray = new int[3,4,2,3]; int Determinant=0; Console.Write("To find out the determinant of a [3,4,2,3] matrix :\n"); Console.Write("Input elements of the matrix by indexing :\n"); for(i=0;i < my4Darray.GetLength(0); i++) { for(j=0;j<3;j++) { Console.Write("element - [{0}],[{1}],[{2}]: ", i,j,k); my4Darray[i,j,k,l] = Convert.ToInt32(Console.ReadLine()); } } Console.Write("The matrix is :\n"); for(j=0; j < my4Darray.GetLength(1);j++) { for(k=0; k < my4Darray.GetLength(2); k++) Console.Write("{0} ",my4Darray[i, j, k,l]); Console.Write("\n"); } for(l=0; l < my4Darray.GetLength(3); l++) //To calculate the determinant hence; Determinant += (my4Darray[0,i,k,l] * (my4Darray[1,(i+1),(k+1),(j+1) % 3] * my4Darray[2,(i+2),(k+2),(j+2) % 3] - my4Darray[1,(i+2),(k+1),(j+2) % 3] * my4Darray[2,(i+1),(k+1),(j+1) % 3])); Console.Write("\nThe Determinant of the matrix is: {0}\n\n", Determinant); //Question2: The determinant squared value Determinant sqr = (Determinant)^2; Console.WriteLine("\n The determinant squared value is: {Determinant sqr}", Determinant); }
public void Determinanttests() { var matrix = new double[6, 6] { { 4, 5, 6, 7, 89, 1 }, { 6, 6, 5, 4, 3, 1 }, { 7, 5, 4, 4, 4, 4 }, { 56, 524, 4, 4, 4, 4 }, { 1, 22, 3, 6, 4, 4 }, { 6, 7, 1, 6, 7, 2 } }; var det = Determinant.Det(matrix); var expeected = -27541428; if (Math.Abs(det - expeected) < Math.Abs(expeected * 0.02)) { Assert.Pass(); } else { Assert.AreEqual(expeected, det); } }
/// <summary> /// Analyzes the specified expression. /// </summary> /// <param name="exp">The expression.</param> /// <returns> /// The result of analysis. /// </returns> /// <exception cref="System.NotSupportedException">Always.</exception> public virtual TResult Analyze(Determinant exp) { throw new NotSupportedException(); }
/// <summary> /// Analyzes the specified expression. /// </summary> /// <param name="exp">The expression.</param> /// <returns>The result of analysis.</returns> public string Analyze(Determinant exp) { return(ToString(exp, "det({0})")); }
/// <summary> /// Creates an expression object from <see cref="FunctionToken"/>. /// </summary> /// <param name="token">The function token.</param> /// <returns>An expression.</returns> protected virtual IExpression CreateFunction(FunctionToken token) { IExpression exp; switch (token.Function) { case Functions.Add: exp = new Add(); break; case Functions.Sub: exp = new Sub(); break; case Functions.Mul: exp = new Mul(); break; case Functions.Div: exp = new Div(); break; case Functions.Pow: exp = new Pow(); break; case Functions.Absolute: exp = new Abs(); break; case Functions.Sine: exp = new Sin(); break; case Functions.Cosine: exp = new Cos(); break; case Functions.Tangent: exp = new Tan(); break; case Functions.Cotangent: exp = new Cot(); break; case Functions.Secant: exp = new Sec(); break; case Functions.Cosecant: exp = new Csc(); break; case Functions.Arcsine: exp = new Arcsin(); break; case Functions.Arccosine: exp = new Arccos(); break; case Functions.Arctangent: exp = new Arctan(); break; case Functions.Arccotangent: exp = new Arccot(); break; case Functions.Arcsecant: exp = new Arcsec(); break; case Functions.Arccosecant: exp = new Arccsc(); break; case Functions.Sqrt: exp = new Sqrt(); break; case Functions.Root: exp = new Root(); break; case Functions.Ln: exp = new Ln(); break; case Functions.Lg: exp = new Lg(); break; case Functions.Lb: exp = new Lb(); break; case Functions.Log: exp = new Log(); break; case Functions.Sineh: exp = new Sinh(); break; case Functions.Cosineh: exp = new Cosh(); break; case Functions.Tangenth: exp = new Tanh(); break; case Functions.Cotangenth: exp = new Coth(); break; case Functions.Secanth: exp = new Sech(); break; case Functions.Cosecanth: exp = new Csch(); break; case Functions.Arsineh: exp = new Arsinh(); break; case Functions.Arcosineh: exp = new Arcosh(); break; case Functions.Artangenth: exp = new Artanh(); break; case Functions.Arcotangenth: exp = new Arcoth(); break; case Functions.Arsecanth: exp = new Arsech(); break; case Functions.Arcosecanth: exp = new Arcsch(); break; case Functions.Exp: exp = new Exp(); break; case Functions.GCD: exp = new GCD(); break; case Functions.LCM: exp = new LCM(); break; case Functions.Factorial: exp = new Fact(); break; case Functions.Sum: exp = new Sum(); break; case Functions.Product: exp = new Product(); break; case Functions.Round: exp = new Round(); break; case Functions.Floor: exp = new Floor(); break; case Functions.Ceil: exp = new Ceil(); break; case Functions.Derivative: exp = new Derivative(); break; case Functions.Simplify: exp = new Simplify(); break; case Functions.Del: exp = new Del(); break; case Functions.Define: exp = new Define(); break; case Functions.Vector: exp = new Vector(); break; case Functions.Matrix: exp = new Matrix(); break; case Functions.Transpose: exp = new Transpose(); break; case Functions.Determinant: exp = new Determinant(); break; case Functions.Inverse: exp = new Inverse(); break; case Functions.If: exp = new If(); break; case Functions.For: exp = new For(); break; case Functions.While: exp = new While(); break; case Functions.Undefine: exp = new Undefine(); break; case Functions.Im: exp = new Im(); break; case Functions.Re: exp = new Re(); break; case Functions.Phase: exp = new Phase(); break; case Functions.Conjugate: exp = new Conjugate(); break; case Functions.Reciprocal: exp = new Reciprocal(); break; case Functions.Min: exp = new Min(); break; case Functions.Max: exp = new Max(); break; case Functions.Avg: exp = new Avg(); break; case Functions.Count: exp = new Count(); break; case Functions.Var: exp = new Var(); break; case Functions.Varp: exp = new Varp(); break; case Functions.Stdev: exp = new Stdev(); break; case Functions.Stdevp: exp = new Stdevp(); break; default: exp = null; break; } if (exp is DifferentParametersExpression diff) { diff.ParametersCount = token.CountOfParams; } return(exp); }
/// <summary> /// Performs simple Gaussian elimination method on a tensor /// /// O(N^3) /// </summary> public T DeterminantGaussianSimple() => Determinant <T, TWrapper> .DeterminantGaussianSimple(this);
/// <summary> /// Computers Laplace's Determinant for all /// matrices in the tensor /// </summary> public GenTensor <T, TWrapper> TensorDeterminantLaplace() => Determinant <T, TWrapper> .TensorDeterminantLaplace(this);
/// <summary> /// Computers Determinant via Guassian elimination and safe division /// for all matrices in the tensor /// </summary> public GenTensor <T, TWrapper> TensorDeterminantGaussianSafeDivision() => Determinant <T, TWrapper> .TensorDeterminantGaussianSafeDivision(this);
/// <summary> /// Computers Determinant via Guassian elimination /// for all matrices in the tensor /// </summary> public GenTensor <T, TWrapper> TensorDeterminantGaussianSimple() => Determinant <T, TWrapper> .TensorDeterminantGaussianSimple(this);