Proektsoftbg / Calcpad

Free and open source software for mathematical and engineering calculations.
https://calcpad.eu
MIT License
382 stars 46 forks source link

Error on matrix determinant calculation #392

Open javila opened 3 days ago

javila commented 3 days ago

Hi!

I was reading the instructions to install Calcpad on Linux and I noticed an error on matrix determinant calculation shown in CLI screenshot example. The correct determinant answer should be -2.

After doing some calculations, I found out that Calcpad is calculating $\det(A) = \det(L)\det(U)$, as I later verified it in GetDeterminant(Matrix lu) function in Calcpad.Core/Matrix/Matrix.cs source code. However, the correct calculation should be $\det(A) = \det(P)\det(L)\det(U)$, where $P$ is the permutation matrix used in LU decomposition.

Proektsoftbg commented 2 days ago

Hi!

Thank you so much for reporting this. You are absolutely right.

I checked and I found that I have missed to account for the determinant sign flips during pivot row interchanges. I will fix this now and issue and update soon. No need to build the P matrix implicitly, there is another way to do this much easier as recommended in the "Numerical Recipes in C" book.

javila commented 2 days ago

Hi!

You are right. You really don't need to build the P matrix.

Proektsoftbg commented 1 day ago

Hi!

This is now fixed in version 7.1.3: https://github.com/Proektsoftbg/Calcpad/releases/tag/v7.1.3

The updated Linux packages are available here: https://github.com/Proektsoftbg/Calcpad/tree/main/Setup/Linux