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 Pragmatic Bookshelf topics Top

New
iPaul
page 37 ANTLRInputStream input = new ANTLRInputStream(is); as of ANTLR 4 .8 should be: CharStream stream = CharStreams.fromStream(i...
New
ianwillie
Hello Brian, I have some problems with running the code in your book. I like the style of the book very much and I have learnt a lot as...
New
joepstender
The generated iex result below should list products instead of product for the metadata. (page 67) iex> product = %Product{} %Pento....
New
New
adamwoolhether
When trying to generate the protobuf .go file, I receive this error: Unknown flag: --go_opt libprotoc 3.12.3 MacOS 11.3.1 Googling ...
New
digitalbias
Title: Build a Weather Station with Elixir and Nerves: Problem connecting to Postgres with Grafana on (page 64) If you follow the defau...
New
rainforest
Hi, I’ve got a question about the implementation of PubSub when using a Phoenix.Socket.Transport behaviour rather than channels. Before ...
New
jwandekoken
Book: Programming Phoenix LiveView, page 142 (157/378), file lib/pento_web/live/product_live/form_component.ex, in the function below: d...
New
SlowburnAZ
Getting an error when installing the dependencies at the start of this chapter: could not compile dependency :exla, "mix compile" failed...
New

Other popular topics Top

AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
New
ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
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
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
Biggest jackpot ever apparently! :upside_down_face: I don’t (usually) gamble/play the lottery, but working on a program to predict the...
New
AstonJ
If you get Can't find emacs in your PATH when trying to install Doom Emacs on your Mac you… just… need to install Emacs first! :lol: bre...
New
First poster: joeb
The File System Access API with Origin Private File System. WebKit supports new API that makes it possible for web apps to create, open,...
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File > New Rule: And select Deny, O...
New

Sub Categories: