rtoy / maxima

A Clone of Maxima's repo
Other
0 stars 0 forks source link

triangularize gives wrong results #3372

Closed rtoy closed 4 months ago

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-07 22:41:01 Created by *anonymous on 2004-11-11 01:05:12 Original: https://sourceforge.net/p/maxima/bugs/646


for example : (%i1) a:matrix([-4,0,-2],[0,1,0],[5,1,3]); [ - 4 0 - 2 ] [ ] (%o1) [ 0
1 0 ] [ ] [ 5 1
3 ] (%i2) determinant(a); (%o2)
- 2 (%i3) t:triangularize(a); [ - 4 0 - 2 ]

[ ] (%o3) [ 0
- 4 0 ]

[ ] [ 0 0 - 2 ]

a and t doesn't even have the same determinant.

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-07 22:41:03 Created by rtoy on 2004-11-11 23:04:20 Original: https://sourceforge.net/p/maxima/bugs/646/#703d


Logged In: YES user_id=28849

Why is this wrong? The result is an upper triangular matrix.

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-07 22:41:06 Created by rtoy on 2004-11-19 21:56:46 Original: https://sourceforge.net/p/maxima/bugs/646/#89fb


Logged In: YES user_id=28849

I can obtain the desired matrix via elementary row operations.

Please cite a reference that says the determinant must match.

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-07 22:41:10 Created by rtoy on 2004-11-20 14:21:49 Original: https://sourceforge.net/p/maxima/bugs/646/#603b


Logged In: YES user_id=28849

For me elementary row operations include swapping rows. That doesn't preserve the determinant.

Anyway, I don't want to argue over this. Convince someone else you are right and have them fix it for you.

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-07 22:41:13 Created by nobody on 2004-11-20 22:33:47 Original: https://sourceforge.net/p/maxima/bugs/646/#e3fa


Logged In: NO

I'm not sure to understand the output %3 but is it saying that the second row is nul ? If so this say that det(trianularize(a))=0 but this impossible because det(a)!=0. Indeed swap rows do *not* conserve det(a) but *do* conserve |det(a)| . So in fact by your argument rtoy your saying that this report *is* a bug. Please consider this (even if the submiter was not really nice) !

Thanks in advance, a ph.d student in maths.

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-07 22:41:17 Created by rtoy on 2004-11-21 14:29:48 Original: https://sourceforge.net/p/maxima/bugs/646/#2c09


Logged In: YES user_id=28849

The bug report doesn't display the actual results very well. The result is matrix([-4, 0, 2],[0,-4,0],[0,0,-2]);

For me, elementary row operations include multiplying a row by a constant. That definitely gives a different determinant.

Anyway, I can obtain the given result by multiplying row 1 by 5 and row 3 by 4 and adding them to give a new matrix, matrix([-4,0,-2],[0,1,0],[0,4,2]). Then multiply row 2 by -4 and add it to row 3 to get matrix([-4,0,-2],[0,1,0],[0,0,2]). Each of these I consider elementary row operations, and clearly the determinant is not the same as the original.

It seems to me you really want a very specific way of triangularizing a matrix.

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-07 22:41:20 Created by nobody on 2004-11-21 16:20:27 Original: https://sourceforge.net/p/maxima/bugs/646/#539b


Logged In: NO

it really seems to me that there is a bug.
Take a matrix A, non singular.

The matrix R is triangularize(A) if, and only if, a matrix Q exist
wich match:
R = Q^-1 * A * Q

Ok with that ?

So, here is the proof that det(A) == det(R):

det(R) = det(Q^-1 * A * Q)
det(R) = det(Q^-1) * det(A) * det(Q)
det(R) = det(Q)^-1 * det(A) * det(Q)
det(R) = det(Q)/det(Q) * det(A)
det(R) = 1 * det(A)

So, det(R) = det(A)

Are you Ok with this demonstration ?

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-07 22:41:24 Created by nobody on 2004-11-21 16:28:05 Original: https://sourceforge.net/p/maxima/bugs/646/#51a4


Logged In: NO

BTW, triangularize is not a LU decomposition ! It seem that there is a such confusion with this thread.

LU decomposition can be obtained by elementary row operations ( with the Gauss pivot algorith ), but I think that the triangularize function should calculate the matrix R as shown as above ( by calculating the eigenvalues/vector ).

So no elementary row operation should be involved with the triangularize function.

rtoy commented 4 months ago

Imported from SourceForge on 2024-07-07 22:41:27 Created by robert_dodier on 2005-11-01 15:50:58 Original: https://sourceforge.net/p/maxima/bugs/646/#37ee


Logged In: YES user_id=501686

triangularize appears to carry out Gaussian elimination, and is observed to yield the same thing as echelon except that the leading coefficient isn't necessarily 1. I've updated Matices.texi to say that. Also the description of triangularize now mentions LU and Cholesky as other things. Closing this report as fixed.