Possible Duplicate:
Calculating an NxN matrix determinant in C#
i want to find determinant of 4x4 matrix in c#
int ss = 4; int count = 0;
int[,] matrix=new int[ss,ss];
ArrayList al = new ArrayList() {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 };
for (int i = 0; i < ss; i++)
{
for (int j = 0; j < ss; j++)
{
matrix[i, j] =Convert.ToInt32( al[count]);
++count;
Response.Write(matrix[i, j] + " ");
}
Response.Write("<br/>");
}
If you're fixed to 4x4, the simplest solution would be to just hardcode the formula.
// assumes matrix indices start from 0 (0,1,2 and 3)
public double determinant(int[,] m) {
return
m[0,3] * m[1,2] * m[2,1] * m[3,0] - m[0,2] * m[1,3] * m[2,1] * m[3,0] -
m[0,3] * m[1,1] * m[2,2] * m[3,0] + m[0,1] * m[1,3] * m[2,2] * m[3,0] +
m[0,2] * m[1,1] * m[2,3] * m[3,0] - m[0,1] * m[1,2] * m[2,3] * m[3,0] -
m[0,3] * m[1,2] * m[2,0] * m[3,1] + m[0,2] * m[1,3] * m[2,0] * m[3,1] +
m[0,3] * m[1,0] * m[2,2] * m[3,1] - m[0,0] * m[1,3] * m[2,2] * m[3,1] -
m[0,2] * m[1,0] * m[2,3] * m[3,1] + m[0,0] * m[1,2] * m[2,3] * m[3,1] +
m[0,3] * m[1,1] * m[2,0] * m[3,2] - m[0,1] * m[1,3] * m[2,0] * m[3,2] -
m[0,3] * m[1,0] * m[2,1] * m[3,2] + m[0,0] * m[1,3] * m[2,1] * m[3,2] +
m[0,1] * m[1,0] * m[2,3] * m[3,2] - m[0,0] * m[1,1] * m[2,3] * m[3,2] -
m[0,2] * m[1,1] * m[2,0] * m[3,3] + m[0,1] * m[1,2] * m[2,0] * m[3,3] +
m[0,2] * m[1,0] * m[2,1] * m[3,3] - m[0,0] * m[1,2] * m[2,1] * m[3,3] -
m[0,1] * m[1,0] * m[2,2] * m[3,3] + m[0,0] * m[1,1] * m[2,2] * m[3,3];
}
You might look at The Answer given the last time you posted this exact same question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With