Parkinbot rudolf at parkinbot.com
Sat Jun 11 20:07:34 EDT 2016

```Are you sure this code ever run properly on a matrix with 0 in diagonal?

look at this trace:

> mx = m4rx(90)*m4ry(90);
> i=0;
> echo(m4inv_solve(0,m4inv_mx(mx)));  // first call evaluated in m4inv(mx)
> echo(i+2<4 && !m4inv_zero(mx[i][i+2]) ? m4inv_solve2(i,
> m4inv_rowswap(i,i+2,mx)):"not taken");  // echo(m4inv_rowswap(i,i+2,mx));
> // d
> echo((i==0) ? mx[i]/mx[i][i]:"not taken");
>
> ECHO: [[0, 0, 1, 0], [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1]] // mx
> ECHO: [[nan, inf, nan, nan, nan, nan, inf, nan], [nan, -inf, nan, nan,
> nan, nan, -inf, nan], [nan, nan, nan, nan, nan, nan, nan, nan], [nan, nan,
> nan, nan, nan, nan, nan, nan]]
> ECHO: [[nan, inf, nan, nan], [nan, -inf, nan, nan], [nan, nan, nan, nan],
> [nan, nan, nan, nan]]
> ECHO: [[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] // row swap
> ECHO: [nan, nan, inf, nan]

So, you test for a column
!m4inv_zero(mx[i][i+2])
then do a row swap
m4inv_rowswap(i,i+2,mx))
and then divide by 0
mx[0]/mx[0][0]

You don't know, what you are "buying" by the row swap.
You should test for the row with first element non-zero and swap this one

--
View this message in context: http://forum.openscad.org/Matrix-inversion-tp17647p17648.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

```