Please help me to write a C++ program which finds the determinant of a n x n Matrix. I'm a beginner in C++ and have read all the posts related to this topic ,but it didn't help me at all. I know the code will be recursive, so i started to solve a 3 x 3 matrix first. Though it is possible to find the determinant without using loops & conditions by applying the formula (first element x (product of .....), i don't find it logical where we could exploit loops and conditions. Hence, i request you to help with the logical part of finding a determinant of n x n matrix.

Recommended Answers

All 3 Replies

Well, You know that the 3 x 3 Matrix could be solved by first element (2x2 Matrix,) -(2nd Element )* (2x2 ) Matix ................

The same applies to the NxN matrix on a large scale,

All you have to do is to.

(first element ) * (Det of (N-1) * (N-1) ) Matrix. - element 2 ......... Element 'n' * (Det of (N-1)* (N-1))

This would go on recursevly. Until you get to the 3x3 or 2x2 matrix where in you can use the formulae,

All you will need to make is a recursive function, which would use a for loop to do the above mentioned thing, until the end results are 2x2 matrix when you can use the formula a*d - b*c to find the determinant.

The other thing that you will have to figure out is on how to send the matrix as an Arguement, I mean how does the Elemination of the ROw And column take place.

Thank you very much for your kind reply.

All you will need to make is a recursive function, which would use a for loop to do the above mentioned thing, until the end results are 2x2 matrix when you can use the formula a*d - b*c to find the determinant

Hence, it's a complicated logic, isn't it ?

The other thing that you will have to figure out is on how to send the matrix as an Arguement, I mean how does the Elemination of the ROw And column take place.

Could i make use of diagonal elements [ (0,0),(1,1),(2,2)....(n,n)] to eliminate Rows and columns ?

Firstly,

>>Hence, it's a complicated logic, isn't it ?
Pardon Me, If my Words make it look kinda complicated,

A trick would be to first determine on how to solve a 4x4 matrix then I guess we will understand on how to accomplish the task.

>>Could i make use of diagonal elements [ (0,0),(1,1),(2,2)....(n,n)] to eliminate Rows and columns ?

Well I am unable to comprehend how diagnol elements will help.

Please stand by for answers from other Daniweb- members too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.