C++ determinant of diagonal matrix

Click For Summary
SUMMARY

The discussion centers on calculating the determinant of an n by n diagonal matrix using C++. The formula for the determinant is established as det[A] = A[0][0]*A[1][1]*A[2][2]*...*A[n][n]. A user initially struggled with implementing a for loop to compute the product of diagonal elements but received guidance that clarified the approach. The final solution involves declaring a variable "diagonal" initialized to 1.0 and multiplying it by each diagonal element within a loop.

PREREQUISITES
  • Understanding of C++ programming language
  • Familiarity with matrix operations
  • Knowledge of Gaussian elimination method
  • Basic concepts of determinants in linear algebra
NEXT STEPS
  • Implement a C++ function to compute determinants of non-diagonal matrices
  • Explore C++ libraries for matrix operations, such as Eigen or Armadillo
  • Learn about advanced matrix factorization techniques
  • Study the implications of determinant properties in linear transformations
USEFUL FOR

Students studying linear algebra, C++ developers working on mathematical computations, and anyone interested in matrix determinant calculations.

jinro
Messages
4
Reaction score
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 a lot once again
 
Last edited:
Physics news on Phys.org
jinro said:
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.
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 18 ·
Replies
18
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 18 ·
Replies
18
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
7K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K