In recent days to learn advanced algebra teacher said to write a program to calculate the determinant of the results, idle to do nothing to simply write a bit.
Not much to say, on the code
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 6 namespaceNROW_CULMN7 {8 class Program9 {Ten Public Static DoubleJlength =0; One Static voidMain (string[] args) A { - //double[,] row_culmn = {{3, 1,-1, 1}, {1,-1, 1, 2}, {2, 1, 2,-1}, {1, 0, 2, 1,}}; - //determinant two-dimensional array the Double[,] row_culmn = {{1,4,9, -}, {4,9, -, -}, {9, -, -, $}, { -, -, $, the} }; - - - + for(inti =0; I <4; i++) - { + for(intj =0; J <4; J + +) A { atConsole.Write (Row_culmn[i, J]. ToString () +" "); - } - Console.WriteLine (); - } - Console.WriteLine (); - Console.WriteLine (); in Console.WriteLine (); - introw =0;//Line to + intRowup =1;//offset column to the right (relative row) -Jlength =math.sqrt (ROW_CULMN. Length); the * for(row =0; Row < Jlength-1; row++) $ {Panax Notoginseng //The recursive algorithm calculates the determinant as the lower triangle is all 0. -VALUEROW_CULMN (refROW_CULMN,refrow, rowup); therowup++; + } A //the value of the calculated determinant double value cannot be equal to 0 by default otherwise all values are zero the DoubleA =1; + for(inti =0; i < jlength; i++) - { $ Console.WriteLine (Row_culmn[i, I]); $A *=row_culmn[i, I]; - } - //formatted output theConsole.WriteLine (string. Format ("{0:f}", a)); - console.readline ();Wuyi the } - Wu Public Static voidVALUEROW_CULMN (ref Double[,] RC,ref intRowintrowup) - { About //Double jlength = math.sqrt (RC. Length); $ DoubleK//coefficients multiplied by columns - if(Rowup <jlength) - { -K =-rc[rowup, row]/rc[row, row]; A for(intj =0; J < Jlength; J + +) + { theRc[rowup, j] + = Rc[row, j] *K; - } $ the Console.WriteLine (); the Console.WriteLine (); the for(intm =0; M <4; m++) the { - for(intj =0; J <4; J + +) in { theConsole.Write (Rc[m, J]. ToString () +" "); the } About Console.WriteLine (); the } the the Console.WriteLine (); +rowup++; -VALUEROW_CULMN (refRcrefrow, rowup); the }Bayi Else the{return; } the } - - the the } the}
Determinant calculation (C #)