#### Archived

This topic is now archived and is closed to further replies.

# 4x4 Determinants

This topic is 5678 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

What are the easy and the fast method to solve a 4x4 determinant?

##### Share on other sites
Laplacian expansion is covered here, and it''s the only method I''ve seen floating around. You can, no doubt, write some very quick C code using only fmuls with this method.

##### Share on other sites
CMatrix3x3 CMatrix4x4:: Minor ( int s,int t )
{
switch ( s )
{
case 0:

switch ( t )
{
case 0:

return CMatrix3x3 (m[ 5],m[ 6],m[ 7],
m[ 9],m[10],m[11],
m[13],m[14],m[15]); break;

case 1:

return CMatrix3x3 (m[ 4],m[ 6],m[ 7],
m[ 8],m[10],m[11],
m[12],m[14],m[15]); break;

case 2:

return CMatrix3x3 (m[ 4],m[ 5],m[ 7],
m[ 8],m[ 9],m[11],
m[12],m[13],m[15]); break;

case 3:

return CMatrix3x3 (m[ 4],m[ 5],m[ 6],
m[ 8],m[ 9],m[10],
m[12],m[13],m[14]); break;
}

break;

case 1:

switch( t )
{
case 0:

return CMatrix3x3 (m[ 1 ],m[ 2],m[ 3],
m[ 9 ],m[10],m[11],
m[ 13],m[14],m[15]);

break;

case 1:

return CMatrix3x3 (m[ 0 ],m[ 2],m[ 3],
m[ 8 ],m[10],m[11],
m[ 12],m[14],m[15]);

break;

case 2:

return CMatrix3x3 (m[ 0 ],m[ 1],m[ 3],
m[ 8 ],m[ 9],m[11],
m[ 12],m[13],m[15]);

break;

case 3:

return CMatrix3x3 (m[ 0 ],m[ 1],m[ 2],
m[ 8 ],m[ 9],m[10],
m[ 12],m[13],m[14]);

break;

}

break;

case 2:

switch ( t )
{
case 0:

return CMatrix3x3 (m[ 1 ],m[ 2],m[ 3],
m[ 5 ],m[ 6],m[ 7],
m[ 13],m[14],m[15]);

break;

case 1:

return CMatrix3x3 (m[ 0 ],m[ 2],m[ 3],
m[ 4 ],m[ 6],m[ 7],
m[ 12],m[14],m[15]);

break;

case 2:

return CMatrix3x3 (m[ 0 ],m[ 1],m[ 3],
m[ 4 ],m[ 5],m[ 7],
m[ 12],m[13],m[15]);

break;

case 3:

return CMatrix3x3 (m[ 0 ],m[ 1],m[ 2],
m[ 4 ],m[ 5],m[ 6],
m[ 12],m[13],m[14]);

break;
}

break;

case 3:

switch (t)
{
case 0:
return CMatrix3x3 (m[ 1 ],m[ 2],m[ 3],
m[ 5 ],m[ 6],m[ 7],
m[ 9 ],m[10],m[11]);

break;

case 1:

return CMatrix3x3 (m[ 0 ],m[ 2],m[ 3],
m[ 4 ],m[ 6],m[ 7],
m[ 8 ],m[10],m[11]);

break;

case 2:

return CMatrix3x3 (m[ 0 ],m[ 1],m[ 3],
m[ 4 ],m[ 5],m[ 7],
m[ 8 ],m[ 9],m[11]);

break;

case 3:

return CMatrix3x3 (m[ 0 ],m[ 1],m[ 2],
m[ 4 ],m[ 5],m[ 6],
m[ 8 ],m[ 9],m[10]);

break;

}

break;

}
////////////////////////////////////
// if s,t are out of range , always
// the first minor is returned

return CMatrix3x3 (m[ 5],m[ 6],m[ 7],
m[ 9],m[10],m[11],
m[13],m[14],m[15]);
}

const float CMatrix4x4::Determinant(void)
{

return ( m[ 0]*(Minor(0,0).Determinant())-
m[ 1]*(Minor(0,1).Determinant())+
m[ 2]*(Minor(0,2).Determinant())-
m[ 3]*(Minor(0,3).Determinant())+
m[ 4]*(Minor(1,0).Determinant())-
m[ 5]*(Minor(1,1).Determinant())+
m[ 6]*(Minor(1,2).Determinant())-
m[ 7]*(Minor(1,3).Determinant())+
m[ 8]*(Minor(2,0).Determinant())-
m[ 9]*(Minor(2,1).Determinant())+
m[10]*(Minor(2,2).Determinant())-
m[11]*(Minor(2,3).Determinant())+
m[12]*(Minor(3,0).Determinant())-
m[13]*(Minor(3,1).Determinant())+
m[14]*(Minor(3,2).Determinant())-
m[15]*(Minor(3,3).Determinant()));

}

here it is

##### Share on other sites
v71, that looks wrong. You need only expand one row or one column.

  const float CMatrix4x4::Determinant(void) {	return	 m[ 0]*(Minor(0,0).Determinant())-	 m[ 1]*(Minor(0,1).Determinant())+	 m[ 2]*(Minor(0,2).Determinant())-	 m[ 3]*(Minor(0,3).Determinant());}

And it would be faster if you don''t construct the matrices, but just get their determinants directly.

##### Share on other sites

float det4x4 (const float d[16])
{
float det1 = d[10]*(d[15]*d[5] - d[7]*d[13]) + d[11]*(d[13]*d[6] - d[5]*d[14]) + d[9]*(d[14]*d[7] - d[6]*d[15]);

float det2 = d[1]*(d[10]*d[15] - d[11]*d[14]) + d[2]*(d[11]*d[13] - d[9]*d[15]) + d[3]*(d[9]*d[14] - d[10]*d[13]);

float det3 = d[1]*(d[6]*d[15] - d[7]*d[14]) + d[2]*(d[7]*d[13] - d[5]*d[15]) + d[3]*(d[5]*d[14] - d[6]*d[13]);

float det4 = d[1]*(d[6]*d[11] - d[7]*d[10]) + d[2]*(d[7]*d[9] - d[5]*d[11]) + d[3]*(d[5]*d[10] - d[6]*d[9]);

return (d[0]*det1 - d[4]*det2 + d[8]*det3 - d[12]*det4);
}

can anyone tell me if this is slower or faster than the v71 - alvaro method?

##### Share on other sites
alvaro , its not wrong, do the calculations and see for yourself,
yes , its faster if you construct the determinats in place,
but my implementation uses a forceinline method.
i''m wearing my antiflame suit

##### Share on other sites
umm, alvaro isn''t wrong, he only tell you that it is unnecessary so many calculations, because for get the determinant, you only need to expand one column or row (4 members), and you have expanded all elements (16), the result is the same, but the calculations are less in alvaro reply and Jess method.

##### Share on other sites
I have implemented Laplace method for solving matrix determinat , it comes with a formula, i ''ve never seen a 4x4 determinant for a single column or a single row, unless you are using a massive gaussian elimination, maybe i''m missing something, i have checked and result *aren''t * the same, i assume you are accepting a ''lowered'' formula because you are not taking into account a factor that would have come out using only a adjoint solution, if someone wants to explain to me , why the determinat is the same, i mean THE SAME i would be gratefull and i''ll fire my linear algebra books, as weel signal processing text.
byez and srry for my english

##### Share on other sites
This is correct matematically, and I see that its exactly the method that has used Jess:

the numbers are the positions, that must be replaced with the numbers, of course.

| 0 4 8 12 |
| 1 5 9 13 |
| 2 6 10 14 | = 0*det0 - 4*det4 + 8*det8 - 12*det12
| 3 7 11 15 |

to solve with Sarrus:
| 5 9 13 |
| 6 10 14 | = det0 (or minor 0)
| 7 11 15 |

| 1 9 13 |
| 2 10 14 | = det4 (or minor 4)
| 3 11 15 |

| 1 5 13 |
| 2 6 14 | = det8 (or minor 8)
| 3 7 15 |

| 1 5 9 |
| 2 6 10 | = det12 (or minor 12)
| 3 7 11 |

##### Share on other sites
i give up . everyone seems to be sure about the solution, have you really tried to do a 4x4 determinat with both methods and compare the results ? i did and the results aren''t the same
check for yourself !!!!
Siete delle teste di cazzo , rincoglioniti

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 13
• 19
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632930
• Total Posts
3009289
• ### Who's Online (See full list)

There are no registered users currently online

×