det(x)

조회 수: 15 (최근 30일)
milad
milad 2015년 8월 18일
댓글: David Goodmanson 2022년 1월 4일
hello dear friends I have a problem with "det(x)". I have tried to descritize an equation with one symbolic variable(A=descritized equation in matrix form contains a symbolic variable and the size of the matrix is 32*32). after descritizing the equation during a process in matlab program , I want to use "det(A)" but the answer is too long and infinity and its not true. but when I bring the matrix "A" to a new separately m-file and I use "det(A)", the answer is true. that is because of the difference value of "det(A)" in the two approaches. since I want to find a lot of answers for different variables, the automatic process is needed absolutely. what is the problem? what should I do to solve the problem? thank you

채택된 답변

Star Strider
Star Strider 2015년 8월 19일
I’m guessing here, but it seems that you may be doing a Cramer’s rule solution to a linear system (or less likely, a linear regression). MATLAB makes this relatively straightforward, so there is no need for you to specifically calculate the determinant.
See specifically the documentation for mldivide and mrdivide for details. There are other functions if your matrices are sparse or have other special conditions you need to consider.

추가 답변 (2개)

John D'Errico
John D'Errico 2015년 8월 19일
Sorry, but how often do I need to say this? DON'T USE DET! It is poorly conditioned in terms of numerics. It is terribly slowly computed when done symbolically. It is virtually useless for anything but basic homework assignments, where students are taught to use an obscenely bad tool for no good reason. Of course, then some of those students go on to write books, teach courses, advise their own students, etc. And of course, they give the wrong advice.
So let me say it three times more. If I say it thrice, it must be true. DON'T USE DET! DON'T USE DET! DON'T USE DET!
Now, you don't say why it is that you THINK you need to use det here. Only that you need it. But the fact is, too often, posters here only THINK they need something. And when somebody tells a story as you have, it is clear that you don't know a lot about numerical analysis, so this makes it very likely that in fact, there are other, far better ways to solve your problem. But we cannot help you, since you have given no useful information in this matter.
  댓글 수: 6
Minati Mishra
Minati Mishra 2021년 12월 29일
any function other than det() to find the determinant of matrix ? det() is not always giving the correct result!
David Goodmanson
David Goodmanson 2022년 1월 4일
Hi Minati,
there is always prod(eig(A)), but if det(A) is bad, the chance that the eig expression is good is not good.

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


Minati Mishra
Minati Mishra 2021년 12월 29일
det([1,2;3 6]) should be 0 but it is giving non-zero value. and this is happening with many more such matrices!
  댓글 수: 2
Christine Tobler
Christine Tobler 2022년 1월 3일
det doesn't have a special branch for 2-by-2 or 3-by-3 matrices, it always uses the same algorithm no matter the matrix size, which has round-off on the level of machine epsilon. To get a computation with zero round-off error, you can use the symbolic toolbox (det(sym([1 2; 3 6]))). When using numeric computation as MATLAB does outside of the symbolic toolbox, using the determinant is discouraged for the reasons John d'Errico explains in the above post: The output of det can only be used as a true/false of "is it exactly zero", and in numeric computations it's nearly always impossible to reliably get an exact zero.
In numeric computations, it's advisable to instead use the condition number, or to directly compute eigenvalues / solve linear systems, which all have reliable numeric algorithms behind them.
Minati Mishra
Minati Mishra 2022년 1월 3일
Thanks!

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

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by