+ 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.
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!
+ 9
Another answer using Gaussian elimination:
https://code.sololearn.com/cyqm3Kaks2dk/?ref=app
On SoloLearn, it works efficiently for matricies as large as 30x30.
+ 6
For a 3×3 matrix only :)
https://code.sololearn.com/ca7sgd63eaQ7/?ref=app
+ 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/#
+ 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