recursion - Computing Array Determinant for NxN Recursive C# -
Well, this is giving me a real headache, I am creating a matrix determinant function to calculate the NxN determiners Am, and I'm using recursive. Logic is working fine, but I can not calculate the final value correctly.
Here is my code for matrix detrimental:
public fixed double assessor (double [,] array) {double det = 0; Double total = 0; Double [,] tempArr = new double [array.GetLength (0) - 1, array.gate lang (1) - 1]; If (array.GetLength (0) == 2) {det = array [0, 0] * array [1, 1] - array [0, 1] * array [1, 0]; } Else {for (int i = 0; i & lt; 1; i ++) {for (int j = 0; j & lt; array.getLength (1); j ++) {if (j% 2! = 0) array [i, j] = array [i, j] * -1; TempArr = fillNewArr (array, i, j); Det + = determinator (tempArr); Total = Total + (date * array [i, j]); }}} Return; } And about the fillNewArr method, there is a method to trim this array, follow the method: P
universal double stable [,] FillNewArr (double [,] original arrows, int row, int colle) {double [,] temaire = new double [original arre. Gate Loughgh (0) - 1, Original Array Gate Lenth (1) - 1]; For (int i = 0, newRow = 0; i & lt; originalArr.GetLength (0); i ++) {if (i == line) is in progress; (Int j = 0, newCol = 0; j & lt; originalArr.GetLength (1); j ++) {if (j == kernel) is released; TempArray [newRow, newCol] = parent ar [i, j]; NewCol ++; } NewRow ++; } Refund Temporary Arms; } This method is considered "I think", but the end result is not counted correctly, why is it ?!
4x4 array example:
{2 6 6 2} {2 7 3 6} {1 5 0} {3 7 7} The end result should be -168, while my 104 is!
this bit
if (that% 2! = 0) Array [i, j] = array [i, j] * -1; TempArr = fillNewArr (array, i, j); Det + = determinator (tempArr); Total = Total + (date * array [i, j]); uses a variable total which is never used again, probably something like this double Subdet = assessor (fillNewArr (array, i, j)); If (that% 2! = 0) is the subdate * = -1; Det + = array [i, j] * subdet;
Comments
Post a Comment