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

 Respuesta aceptada

Star Strider
Star Strider el 19 de Ag. de 2015

0 votos

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.

Más respuestas (2)

John D'Errico
John D'Errico el 19 de Ag. de 2015

2 votos

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 comentarios

milad
milad el 19 de Ag. de 2015
thank you for your punishment :-). I know that the best way to find the solution in an eigen-value problem is use of "eig" in the following relation: "[[A]-landa[B]]{x}=0". but the matrix "[B]" is a non-invertible matrix. so as you know I've got to use "pinv(B)" or some other ways such as "[B]\[I]" which might give inexact answers. for this reason and assurance, I want to test two or more approaches to find the best and exact solution. thank you for your guidance
Torsten
Torsten el 19 de Ag. de 2015
What's wrong with eig(A,B) for generalized eigenvalue problems ?
Best wishes
Torsten.
John D'Errico
John D'Errico el 19 de Ag. de 2015
Editada: John D'Errico el 19 de Ag. de 2015
I thought you did not have a valid reason for this use of det. I was right.
As Torsten said, why not use eig(A,B)?
That B is singular says that there will not be a complete set of solutions. There is no "best and exact solution", better than what you will get from eig.
A= rand(3)
A =
0.96489 0.95717 0.14189
0.15761 0.48538 0.42176
0.97059 0.80028 0.91574
B = ones(3);
eig(A,B)
ans =
0.70874
Inf
Inf
Trying to do this symbolically is a silly task, when eig gives you the solution in double precision.
milad
milad el 19 de Ag. de 2015
I solved it with "det". The problem was the name of m-file which was selected as "solve" and also using "vpa" in the descritized form of equations. But the best way is to use "eig(A,B) " which is so faster than "det". Thank you guys for your attention and very helpful and useful guidance. Best Regards
Minati Mishra
Minati Mishra el 29 de Dic. de 2021
any function other than det() to find the determinant of matrix ? det() is not always giving the correct result!
David Goodmanson
David Goodmanson el 4 de En. de 2022
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.

Iniciar sesión para comentar.

Minati Mishra
Minati Mishra el 29 de Dic. de 2021

0 votos

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 comentarios

Christine Tobler
Christine Tobler el 3 de En. de 2022
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 el 3 de En. de 2022
Thanks!

Iniciar sesión para comentar.

Categorías

Más información sobre Linear Algebra en Centro de ayuda y File Exchange.

Preguntada:

el 18 de Ag. de 2015

Comentada:

el 4 de En. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by