Code for determinant.

조회 수: 39 (최근 30일)
eden hazard
eden hazard 2018년 11월 14일
댓글: Walter Roberson 2021년 2월 26일
I would like to built a code to find the determinant of a 24x24 matrix.I dont want to use the det(X) function,but a fuction that would be quick.
The one i created,whick is too slow for that.
  댓글 수: 2
Stephen23
Stephen23 2018년 11월 15일
"I dont want to use the det(X) function,but a function that would be quick."
Ah, the sweet, blind optimism of youth.
Have you actually looked at the definition of the determinant, and figured out how many calculations it would require for a 24x24 matrix? When is your estimated completion?
eden hazard
eden hazard 2018년 11월 15일
Haha it is the optimism of my teacher. The fuction should calculate the determinant in 5-30 minutes

댓글을 달려면 로그인하십시오.

채택된 답변

John D'Errico
John D'Errico 2018년 11월 15일
NO NO NO!!!!!
First, you should not be using the determinant here. I don't know why you think you need to use it. But if you don't understand how to efficiently compute a determinant, the probability is 1 that you should not be using the determinant in the first place. There are far better tools to determine is amatrix issingular, which is why you are surely wanting to compute the determinant of a 24x24 matrix.
Ok, why is the code you wrote a an obscenely bad one? Do you understand that the code you wrote will require O(factorial(24)) computations to execute?
factorial(24)
ans =
6.20448401733239e+23
Even the largest supercomputer the NSA owns would grind to a miserable halt.
So, CAN you compute the determinant more efficiently? Well, yes. USE DET! (In fact there are ways to compute the determinant efficiently. But since you should not be using it in the first place, I won't go into details.)
So better yet, don't compute the determianant at all. So instead, you need to learn how to use tools like rank, cond or svd to do what you are trying to do. Of course, we don't really yet know what you are doing.
  댓글 수: 6
James Tursa
James Tursa 2018년 11월 15일
편집: James Tursa 2018년 11월 15일
My teacher in college once described the minors/cofactor method to me this way:
"Well, it may be slow, but it's innacurate!"
Steven Lord
Steven Lord 2018년 11월 16일
"innaccurate" as in "start it computing, go to bed, and maybe you'll have something close to right when you wake up?" grin

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Reza Lashani
Reza Lashani 2021년 2월 3일
편집: Reza Lashani 2021년 2월 3일
One of the fastest ways to determine the determinant of a matrix is doing row operation. For an invertible matrix we know that row operations finally reach to identity matrix which has determinant equal to 1. For calculating determinant we can write an efficient and of course fast code to do row operation and it is not necessary to make the first non-zero entry 1 by dividing it by itself. It cause we finally reach to a diagonal matrix (stead of identity matrix) and the determinant is equal to the product of pivots of the final matrix. Doing this algorithm on my ordinary system for a 24 × 24 matrix lates less than 1 second.
  댓글 수: 4
mahdi moshtoghi
mahdi moshtoghi 2021년 2월 26일
hey, how to write the determinan 4*4 and 3*3 on matlab?
Walter Roberson
Walter Roberson 2021년 2월 26일
syms A [3 3]
syms B [4 4]
simplify(det(A))
ans = 
simplify(det(B))
ans = 

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by