| View previous topic :: View next topic |
| Author |
Message |
rikstick Guest
|
Posted: Mon Dec 20, 2004 12:48 am Post subject: function that returns the determinant of a matrix |
|
|
Does anyone know of a function that will return the determinant of a
double scripted matrix with dimensions of 3x3 or greater? I would
really appreciate the source code if you know of such a function.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
NJS Guest
|
Posted: Tue Dec 21, 2004 10:31 am Post subject: Re: function that returns the determinant of a matrix |
|
|
Type in "determinant cofactor expansion" into google, and you'll get
links to a technique for solving determinants for arbitrary NxN
matrices. There are probably numerically better ways of doing this.
Personally, I would just use a linear algebra package; try searching on
"LAPACK".
- Niek Sanders
rikstick wrote:
| Quote: | Does anyone know of a function that will return the determinant of a
double scripted matrix with dimensions of 3x3 or greater? I would
really appreciate the source code if you know of such a function.
|
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Branimir Maksimovic Guest
|
Posted: Tue Dec 21, 2004 10:33 am Post subject: Re: function that returns the determinant of a matrix |
|
|
rikstick wrote:
| Quote: | Does anyone know of a function that will return the determinant of a
double scripted matrix with dimensions of 3x3 or greater? I would
really appreciate the source code if you know of such a function.
|
One of my first steps in c++ back in 1994 was writing
matrix class and calculating determinant, inverse matrix
and such things. Is this some homework question ?
Just look at the neariest math book and write that
thing as you already know what is double scripted matrix.
Greetings, Bane.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Francis Glassborow Guest
|
Posted: Wed Dec 22, 2004 2:54 am Post subject: Re: function that returns the determinant of a matrix |
|
|
In article <1103561473.539641.158930 (AT) z14g2000cwz (DOT) googlegroups.com>, NJS
<njs8030 (AT) yahoo (DOT) com> writes
| Quote: | Type in "determinant cofactor expansion" into google, and you'll get
links to a technique for solving determinants for arbitrary NxN
matrices. There are probably numerically better ways of doing this.
Personally, I would just use a linear algebra package; try searching on
"LAPACK".
|
Many years ago I came across the case of a student at an Australian
university doing an engineering degree who kept exceeding his resource
limits. He was very puzzled because he had tested his code for
evaluating an n by n determinant and it worked fine. However, whenever
he tried to apply it to his engineering problem he exceeded his resource
allowance and had to go to his supervisor for more. The third time this
happened his supervisor asked to see the code.
He had written a simple recursive expansion using co-factors. Tested it
with 3x3, 4x4 and 5x5 test cases. He then tried to apply it to the real
problem that was a 24x24. I seriously doubt that there is any machine in
existence today that could evaluate a 24x24 determinant by cofactor
expansion.
C++ is not a miracle language. Solving problems requires expertise in
the problem domain as well as in C++. The OP will need to study a bit
more math before cutting code.
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
NJS Guest
|
Posted: Thu Dec 23, 2004 9:13 pm Post subject: Re: function that returns the determinant of a matrix |
|
|
You're right about cofactor expansion being the wrong tool for the job.
I knew using cofactors would be expensive, but it didn't occur to me
that the algorithm is factorial.
According to Maple and my friendly linear algebra textbook, a more
reasonable approach is using gaussian elimination (through LU
decomposition), which leads to a polynomial time algorithm.
- Niek
Francis Glassborow wrote:
[snip]
| Quote: |
He had written a simple recursive expansion using co-factors. Tested
it
with 3x3, 4x4 and 5x5 test cases. He then tried to apply it to the
real
problem that was a 24x24. I seriously doubt that there is any machine
in
existence today that could evaluate a 24x24 determinant by cofactor
expansion.
[snip] |
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|