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?

1 797 3

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 Prag Prog topics Top

jimmykiang
This test is broken right out of the box… — FAIL: TestAgent (7.82s) agent_test.go:77: Error Trace: agent_test.go:77 agent_test.go:...
4 1547 7
New
johnp
Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’. In particula...
5 3524 1
New
sdmoralesma
Title: Web Development with Clojure, Third Edition - migrations/create not working: p159 When I execute the command: user=> (create-...
5 1082 2
New
jskubick
I think I might have found a problem involving SwitchCompat, thumbTint, and trackTint. As entered, the SwitchCompat changes color to hol...
0 2600 2
New
Charles
In general, the book isn’t yet updated for Phoenix version 1.6. On page 18 of the book, the authors indicate that an auto generated of ro...
9 2047 12
New
brunogirin
When trying to run tox in parallel as explained on page 151, I got the following error: tox: error: argument -p/–parallel: expected one...
0 1102 1
New
oaklandgit
Hi, I completed chapter 6 but am getting the following error when running: thread 'main' panicked at 'Failed to load texture: IoError(O...
2 1302 3
New
rainforest
Hi, I’ve got a question about the implementation of PubSub when using a Phoenix.Socket.Transport behaviour rather than channels. Before ...
0 1488 3
New
a.zampa
@mfazio23 I’m following the indications of the book and arriver ad chapter 10, but the app cannot be compiled due to an error in the Bas...
1 3324 6
New
davetron5000
Hello faithful readers! If you have tried to follow along in the book, you are asked to start up the dev environment via dx/build and ar...
3 1149 19
New

Other popular topics Top

Devtalk
Hello Devtalk World! Please let us know a little about who you are and where you’re from :nerd_face:
476 5521 111
New
AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
74 4637 41
New
AstonJ
Or looking forward to? :nerd_face:
480 9107 251
New
Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
36 5150 10
New
foxtrottwist
Here’s our thread for the Keyboardio Atreus. It is a mechanical keyboard based on and a slight update of the original Atreus (Keyboardio ...
9 3083 6
New
AstonJ
I ended up cancelling my Moonlander order as I think it’s just going to be a bit too bulky for me. I think the Planck and the Preonic (o...
105 14022 47
New
Margaret
Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
110 3689 43
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
91 4884 43
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
4 3434 1
New
PragmaticBookshelf
A Ruby-Centric Chat with Noel Rappin @noelrappin Once you start noodling around with Ruby you quickly figure out, as Noel Rappi...
41 2556 20
New

Latest in PragProg

View all threads ❯