C++ determinant of diagonal matrix

  • Comp Sci
  • Thread starter jinro
  • Start date
  • #1
4
0

Homework Statement


well, my assignment was to make a gauss elimination, so now i need to compute the determinant of an n by n diagonal matrix

variable rows = number of equations
variable i = random integer
matrix A[100][100]
dummy matrix A2[100][100]

Homework Equations



det[A] = A[0][0]*A[1][1]*A[2][2]*........*A[n][n]

The Attempt at a Solution


i made the code for pivoting and forward elimination, but i spent 2 hours or so and i couldn't figure out how to make a code for this using for loop

for (i=0;i<rows;i++){
A2 = A*A[i+1][i+1]
}
(this will only ever give me a product of 2 numbers in the diagonal though)

i thought it was going to be easy but i need to find a formula so it stores the products of all the elements in the diagonal of the matrix

PS; there is only so much attempts i can show, since i have no clue whatsoever to go about this.




@borek

thanks a lot i got the answer u helped a lot, i also realized my back elimination formula was wrong and your method helped me alot once again
 
Last edited:

Answers and Replies

  • #2
Borek
Mentor
28,830
3,350
det[A] = A[0][0]*A[1][1]*A[2][2]*........*A[n][n]

Declare variable "diagonal", init it with 1.0, multiply it in loop by all diagonal elements.
 

Related Threads on C++ determinant of diagonal matrix

Replies
2
Views
6K
Replies
18
Views
979
  • Last Post
Replies
7
Views
2K
Replies
14
Views
2K
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
6
Views
3K
Replies
7
Views
7K
Replies
5
Views
977
Replies
2
Views
3K
Replies
5
Views
1K
Top