+ 16

🔴CHALLENGE 🔴 Determinant of a Random Matrix

It would be a shame if we don't have a challenge for computing determinants of matrices in SoloLearn. So Let's write a program which receives a natural number N between 2 and 10 (due to obvious compiler/memory restrictions!) and generates a square (N by N) matrix and prints it and computes and prints its determinant. The obvious approach would be a recursive algorithm for computing determinant of a matrix by computing the determinants of its minor matrices. This algorithm has been implemented in the following C++ code. There is also another approach which is based on permutations, which requires generating all permutations of N letters. I apologize in advance for not being able to check the accuracy of every submitted code.

18th Dec 2017, 10:16 AM
Vahid Shirbisheh
Vahid Shirbisheh - avatar
6 odpowiedzi
+ 10
My try using C++: I choose entries of the matrix among integers between -9 and +9 randomly. My code should work for matrices as large as 10x10. https://code.sololearn.com/cHlrfGX3p45b Comments and suggestions are welcomed!
18th Dec 2017, 10:19 AM
Vahid Shirbisheh
Vahid Shirbisheh - avatar
+ 9
Another answer using Gaussian elimination: https://code.sololearn.com/cyqm3Kaks2dk/?ref=app On SoloLearn, it works efficiently for matricies as large as 30x30.
20th Dec 2017, 1:29 PM
Vahid Shirbisheh
Vahid Shirbisheh - avatar
7th Jan 2018, 11:53 AM
Abhishek Tandon
Abhishek Tandon - avatar
+ 2
I tried this in C++ My code is definitely not the most efficient but this was the only way I could figure it out as of now https://code.sololearn.com/crDglE1CnlvY/#
19th Dec 2017, 10:05 PM
Anne Hirata
+ 2
Here is my try in Python, I used the symetric group and permutations method, I thought It would be too slow but It doesnt seem that bad, Tell me if there are any mistakes =D By the way, with random elements between -9 and 9 the determinant is always a pretty Big number lol. https://code.sololearn.com/cvZgyJLLGla8/?ref=app
21st Dec 2017, 8:18 PM
Lucas Pardo
Lucas Pardo - avatar