FPChris

FPChris

The Ray Tracer Challenge: Page 37 4x4 cofactor?

On Page 37. How to calculate the cofactor for a 4x4 matrix is never shown. Only the 3x3.
How is the author getting the cofactor(A,0,0) = 690 section? and then the determinant -4071?

Marked As Solved

FPChris

FPChris

I finally resolved this. The book is really unclear. Terrible in fact.
If anyone needs hep on this. Here is my solution below.
This YT video was a great help Finding the determinant of a 3x3 matrix method 2 | Matrices | Precalculus | Khan Academy - YouTube

//-----------------------------------------------------------------------------------
function RCCalcCofactor4x4(A,row,col){

let B = RCGetSubmatrix4x3(A,row,col); //4x4 > 3x3
let s,a;
s = RCGetSubmatrix3x2(B,0,0); //3x3 to 2x2
a = B[0][0] * RCCalcDeterminant2x2(s);
s = RCGetSubmatrix3x2(B,0,1);
a += -B[0][1] * RCCalcDeterminant2x2(s); //Note: -B
s = RCGetSubmatrix3x2(B,0,2);
a += B[0][2] * RCCalcDeterminant2x2(s);

if(isOdd(row + col)){ return -a; } //odd so negate
return a; //even - leave alone. just return it

}
//-----------------------------------------------------------------------------------
function isOdd(num) { return num % 2;}
//-----------------------------------------------------------------------------------
function RCCalcDeterminant4x4(A){
// Ch 3 - page 37
/*
A[0][0] = -2; A[0][1] = -8; A[0][2] = 3; A[0][3] = 5;
A[1][0] = -3; A[1][1] = 1; A[1][2] = 7; A[1][3] = 3;
A[2][0] = 1; A[2][1] = 2; A[2][2] = -9; A[2][3] = 6;
A[3][0] = -6; A[3][1] = 7; A[3][2] = 7; A[3][3] = -9;
*/

let d0 = RCCalcCofactor4x4(A,0,0); //690
let d1 = RCCalcCofactor4x4(A,0,1); //447
let d2 = RCCalcCofactor4x4(A,0,2); //210
let d3 = RCCalcCofactor4x4(A,0,3); //51

let d = (A[0][0] * d0) + (A[0][1] * d1) + (A[0][2] * d2) + (A[0][3] * d3); //-4071

return d;

}

Also Liked

FPChris

FPChris

Thanks. I think I struggled mostly throughout with being presented with a test and not realizing they would fail initially and that solutions where sometimes pages away. I eventually caught on to this and began reading through several more pages before coding a new topic.

Popular Community topics Top

New

Other popular topics Top

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1017 16962 374
New
AstonJ
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face: Perhaps if there’s enough peop...
New
AstonJ
Inspired by this post from @Carter, which languages, frameworks or other tech or tools do you think is killing it right now? :upside_down...
New
Exadra37
Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
New
AstonJ
Seems like a lot of people caught it - just wondered whether any of you did? As far as I know I didn’t, but it wouldn’t surprise me if I...
New
OvermindDL1
Woooooooo! This is such a huge release for it, and 2 years incoming! In short, the library is now using an updated hyper backend (not j...
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
AstonJ
Saw this on TikTok of all places! :lol: Anyone heard of them before? Lite:
New
DevotionGeo
I have always used antique keyboards like Cherry MX 1800 or Cherry MX 8100 and almost always have modified the switches in some way, like...
New
PragmaticBookshelf
Author Spotlight: Tammy Coron @Paradox927 Gaming, and writing games in particular, is about passion, vision, experience, and immersio...
New