discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

inverse matrix

SP
Sanjeev Prabhakar
Sat, Feb 8, 2025 4:43 AM

I feel the inverse of a matrix should be part of the mathematical functions
in stock openSCAD.

That is not too difficult to do I suppose and makes the calculations
related to linear algebra much simpler.

I realised this while trying to calculate the intersection point between 2
straight lines, where 2 simple equations with 2 unknowns need to be
calculated.

It is possible to do such calculations by hand but would be much simpler if
that can be part of the software algorithm.

Thanks

I feel the inverse of a matrix should be part of the mathematical functions in stock openSCAD. That is not too difficult to do I suppose and makes the calculations related to linear algebra much simpler. I realised this while trying to calculate the intersection point between 2 straight lines, where 2 simple equations with 2 unknowns need to be calculated. It is possible to do such calculations by hand but would be much simpler if that can be part of the software algorithm. Thanks
AM
Adrian Mariano
Sat, Feb 8, 2025 4:46 AM

I implemented QR factorization in BOSL2, which makes it possible to solve
linear systems of equations, and in the rare case you need it, to compute a
matrix inverse as well.  (Note: matrix inverses should generally be avoided
because they are computationally inefficient and also less accurate.)

On Fri, Feb 7, 2025 at 11:43 PM Sanjeev Prabhakar via Discuss <
discuss@lists.openscad.org> wrote:

I feel the inverse of a matrix should be part of the mathematical
functions in stock openSCAD.

That is not too difficult to do I suppose and makes the calculations
related to linear algebra much simpler.

I realised this while trying to calculate the intersection point between 2
straight lines, where 2 simple equations with 2 unknowns need to be
calculated.

It is possible to do such calculations by hand but would be much simpler
if that can be part of the software algorithm.

Thanks


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

I implemented QR factorization in BOSL2, which makes it possible to solve linear systems of equations, and in the rare case you need it, to compute a matrix inverse as well. (Note: matrix inverses should generally be avoided because they are computationally inefficient and also less accurate.) On Fri, Feb 7, 2025 at 11:43 PM Sanjeev Prabhakar via Discuss < discuss@lists.openscad.org> wrote: > I feel the inverse of a matrix should be part of the mathematical > functions in stock openSCAD. > > That is not too difficult to do I suppose and makes the calculations > related to linear algebra much simpler. > > I realised this while trying to calculate the intersection point between 2 > straight lines, where 2 simple equations with 2 unknowns need to be > calculated. > > It is possible to do such calculations by hand but would be much simpler > if that can be part of the software algorithm. > > Thanks > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
SP
Sanjeev Prabhakar
Sat, Feb 8, 2025 5:59 AM

Only when the determinant is zero it is not possible to calculate inverse.
But there is a way to avoid that easily if you Rotate the model by very
small amount maybe .0001 deg.

On Sat, 8 Feb, 2025, 10:17 am Adrian Mariano via Discuss, <
discuss@lists.openscad.org> wrote:

I implemented QR factorization in BOSL2, which makes it possible to solve
linear systems of equations, and in the rare case you need it, to compute a
matrix inverse as well.  (Note: matrix inverses should generally be avoided
because they are computationally inefficient and also less accurate.)

On Fri, Feb 7, 2025 at 11:43 PM Sanjeev Prabhakar via Discuss <
discuss@lists.openscad.org> wrote:

I feel the inverse of a matrix should be part of the mathematical
functions in stock openSCAD.

That is not too difficult to do I suppose and makes the calculations
related to linear algebra much simpler.

I realised this while trying to calculate the intersection point between
2 straight lines, where 2 simple equations with 2 unknowns need to be
calculated.

It is possible to do such calculations by hand but would be much simpler
if that can be part of the software algorithm.

Thanks


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Only when the determinant is zero it is not possible to calculate inverse. But there is a way to avoid that easily if you Rotate the model by very small amount maybe .0001 deg. On Sat, 8 Feb, 2025, 10:17 am Adrian Mariano via Discuss, < discuss@lists.openscad.org> wrote: > I implemented QR factorization in BOSL2, which makes it possible to solve > linear systems of equations, and in the rare case you need it, to compute a > matrix inverse as well. (Note: matrix inverses should generally be avoided > because they are computationally inefficient and also less accurate.) > > On Fri, Feb 7, 2025 at 11:43 PM Sanjeev Prabhakar via Discuss < > discuss@lists.openscad.org> wrote: > >> I feel the inverse of a matrix should be part of the mathematical >> functions in stock openSCAD. >> >> That is not too difficult to do I suppose and makes the calculations >> related to linear algebra much simpler. >> >> I realised this while trying to calculate the intersection point between >> 2 straight lines, where 2 simple equations with 2 unknowns need to be >> calculated. >> >> It is possible to do such calculations by hand but would be much simpler >> if that can be part of the software algorithm. >> >> Thanks >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
GS
Guenther Sohler
Sat, Feb 8, 2025 6:51 AM

In pythonscad there has been "divmatrix" next to multmatrix for  a long
time and it exactly serves that purpose

On Sat, Feb 8, 2025 at 5:44 AM Sanjeev Prabhakar via Discuss <
discuss@lists.openscad.org> wrote:

I feel the inverse of a matrix should be part of the mathematical
functions in stock openSCAD.

That is not too difficult to do I suppose and makes the calculations
related to linear algebra much simpler.

I realised this while trying to calculate the intersection point between 2
straight lines, where 2 simple equations with 2 unknowns need to be
calculated.

It is possible to do such calculations by hand but would be much simpler
if that can be part of the software algorithm.

Thanks


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

In pythonscad there has been "divmatrix" next to multmatrix for a long time and it exactly serves that purpose On Sat, Feb 8, 2025 at 5:44 AM Sanjeev Prabhakar via Discuss < discuss@lists.openscad.org> wrote: > I feel the inverse of a matrix should be part of the mathematical > functions in stock openSCAD. > > That is not too difficult to do I suppose and makes the calculations > related to linear algebra much simpler. > > I realised this while trying to calculate the intersection point between 2 > straight lines, where 2 simple equations with 2 unknowns need to be > calculated. > > It is possible to do such calculations by hand but would be much simpler > if that can be part of the software algorithm. > > Thanks > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
AM
Adrian Mariano
Sat, Feb 8, 2025 12:57 PM

Sanjeev, you can calculate the inverse, sure, but if you are trying to
solve an equation like Ax=b you should NOT calculate the inverse and
compute inverse(A)*b because this is an inaccurate and slow way to get the
solution to that problem.  It is a numerically unstable method for solving
the problem.  And computing the inverse actually requires solving a whole
series of Ax=b problems.

On Sat, Feb 8, 2025 at 1:51 AM Guenther Sohler via Discuss <
discuss@lists.openscad.org> wrote:

In pythonscad there has been "divmatrix" next to multmatrix for  a long
time and it exactly serves that purpose

On Sat, Feb 8, 2025 at 5:44 AM Sanjeev Prabhakar via Discuss <
discuss@lists.openscad.org> wrote:

I feel the inverse of a matrix should be part of the mathematical
functions in stock openSCAD.

That is not too difficult to do I suppose and makes the calculations
related to linear algebra much simpler.

I realised this while trying to calculate the intersection point between
2 straight lines, where 2 simple equations with 2 unknowns need to be
calculated.

It is possible to do such calculations by hand but would be much simpler
if that can be part of the software algorithm.

Thanks


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Sanjeev, you can calculate the inverse, sure, but if you are trying to solve an equation like Ax=b you should NOT calculate the inverse and compute inverse(A)*b because this is an inaccurate and slow way to get the solution to that problem. It is a numerically unstable method for solving the problem. And computing the inverse actually requires solving a whole series of Ax=b problems. On Sat, Feb 8, 2025 at 1:51 AM Guenther Sohler via Discuss < discuss@lists.openscad.org> wrote: > In pythonscad there has been "divmatrix" next to multmatrix for a long > time and it exactly serves that purpose > > > > > On Sat, Feb 8, 2025 at 5:44 AM Sanjeev Prabhakar via Discuss < > discuss@lists.openscad.org> wrote: > >> I feel the inverse of a matrix should be part of the mathematical >> functions in stock openSCAD. >> >> That is not too difficult to do I suppose and makes the calculations >> related to linear algebra much simpler. >> >> I realised this while trying to calculate the intersection point between >> 2 straight lines, where 2 simple equations with 2 unknowns need to be >> calculated. >> >> It is possible to do such calculations by hand but would be much simpler >> if that can be part of the software algorithm. >> >> Thanks >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
SP
Sanjeev Prabhakar
Sat, Feb 8, 2025 3:04 PM

I agree on speed but I am really wondering what has lead you to such a
conclusion about the accuracy.

Although I use 2 different ways to calculate intersections. Inverse matrix
method takes longer but the results are comparable with direct calculation
method by a derived formulae and it is much simpler to work with, atleast
in python.

I am not sure about openscad.

If there is any other method, which is better and faster, it will be
interesting to know.

On Sat, 8 Feb, 2025, 6:28 pm Adrian Mariano via Discuss, <
discuss@lists.openscad.org> wrote:

Sanjeev, you can calculate the inverse, sure, but if you are trying to
solve an equation like Ax=b you should NOT calculate the inverse and
compute inverse(A)*b because this is an inaccurate and slow way to get the
solution to that problem.  It is a numerically unstable method for solving
the problem.  And computing the inverse actually requires solving a whole
series of Ax=b problems.

On Sat, Feb 8, 2025 at 1:51 AM Guenther Sohler via Discuss <
discuss@lists.openscad.org> wrote:

In pythonscad there has been "divmatrix" next to multmatrix for  a long
time and it exactly serves that purpose

On Sat, Feb 8, 2025 at 5:44 AM Sanjeev Prabhakar via Discuss <
discuss@lists.openscad.org> wrote:

I feel the inverse of a matrix should be part of the mathematical
functions in stock openSCAD.

That is not too difficult to do I suppose and makes the calculations
related to linear algebra much simpler.

I realised this while trying to calculate the intersection point between
2 straight lines, where 2 simple equations with 2 unknowns need to be
calculated.

It is possible to do such calculations by hand but would be much simpler
if that can be part of the software algorithm.

Thanks


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

I agree on speed but I am really wondering what has lead you to such a conclusion about the accuracy. Although I use 2 different ways to calculate intersections. Inverse matrix method takes longer but the results are comparable with direct calculation method by a derived formulae and it is much simpler to work with, atleast in python. I am not sure about openscad. If there is any other method, which is better and faster, it will be interesting to know. On Sat, 8 Feb, 2025, 6:28 pm Adrian Mariano via Discuss, < discuss@lists.openscad.org> wrote: > Sanjeev, you can calculate the inverse, sure, but if you are trying to > solve an equation like Ax=b you should NOT calculate the inverse and > compute inverse(A)*b because this is an inaccurate and slow way to get the > solution to that problem. It is a numerically unstable method for solving > the problem. And computing the inverse actually requires solving a whole > series of Ax=b problems. > > On Sat, Feb 8, 2025 at 1:51 AM Guenther Sohler via Discuss < > discuss@lists.openscad.org> wrote: > >> In pythonscad there has been "divmatrix" next to multmatrix for a long >> time and it exactly serves that purpose >> >> >> >> >> On Sat, Feb 8, 2025 at 5:44 AM Sanjeev Prabhakar via Discuss < >> discuss@lists.openscad.org> wrote: >> >>> I feel the inverse of a matrix should be part of the mathematical >>> functions in stock openSCAD. >>> >>> That is not too difficult to do I suppose and makes the calculations >>> related to linear algebra much simpler. >>> >>> I realised this while trying to calculate the intersection point between >>> 2 straight lines, where 2 simple equations with 2 unknowns need to be >>> calculated. >>> >>> It is possible to do such calculations by hand but would be much simpler >>> if that can be part of the software algorithm. >>> >>> Thanks >>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
GS
Guenther Sohler
Sat, Feb 8, 2025 3:15 PM

I am Wondering after all, why you need Matrix Inversion in Openscad, when
there Is in numpy.

Am Samstag, 8. Februar 2025 schrieb Sanjeev Prabhakar via Discuss <
discuss@lists.openscad.org>:

I agree on speed but I am really wondering what has lead you to such a
conclusion about the accuracy.

Although I use 2 different ways to calculate intersections. Inverse matrix
method takes longer but the results are comparable with direct calculation
method by a derived formulae and it is much simpler to work with, atleast
in python.

I am not sure about openscad.

If there is any other method, which is better and faster, it will be
interesting to know.

On Sat, 8 Feb, 2025, 6:28 pm Adrian Mariano via Discuss, <
discuss@lists.openscad.org> wrote:

Sanjeev, you can calculate the inverse, sure, but if you are trying to
solve an equation like Ax=b you should NOT calculate the inverse and
compute inverse(A)*b because this is an inaccurate and slow way to get the
solution to that problem.  It is a numerically unstable method for solving
the problem.  And computing the inverse actually requires solving a whole
series of Ax=b problems.

On Sat, Feb 8, 2025 at 1:51 AM Guenther Sohler via Discuss <
discuss@lists.openscad.org> wrote:

In pythonscad there has been "divmatrix" next to multmatrix for  a long
time and it exactly serves that purpose

On Sat, Feb 8, 2025 at 5:44 AM Sanjeev Prabhakar via Discuss <
discuss@lists.openscad.org> wrote:

I feel the inverse of a matrix should be part of the mathematical
functions in stock openSCAD.

That is not too difficult to do I suppose and makes the calculations
related to linear algebra much simpler.

I realised this while trying to calculate the intersection point
between 2 straight lines, where 2 simple equations with 2 unknowns need to
be calculated.

It is possible to do such calculations by hand but would be much
simpler if that can be part of the software algorithm.

Thanks


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

--
Null

I am Wondering after all, why you need Matrix Inversion in Openscad, when there Is in numpy. Am Samstag, 8. Februar 2025 schrieb Sanjeev Prabhakar via Discuss < discuss@lists.openscad.org>: > I agree on speed but I am really wondering what has lead you to such a > conclusion about the accuracy. > > Although I use 2 different ways to calculate intersections. Inverse matrix > method takes longer but the results are comparable with direct calculation > method by a derived formulae and it is much simpler to work with, atleast > in python. > > I am not sure about openscad. > > If there is any other method, which is better and faster, it will be > interesting to know. > > > On Sat, 8 Feb, 2025, 6:28 pm Adrian Mariano via Discuss, < > discuss@lists.openscad.org> wrote: > >> Sanjeev, you can calculate the inverse, sure, but if you are trying to >> solve an equation like Ax=b you should NOT calculate the inverse and >> compute inverse(A)*b because this is an inaccurate and slow way to get the >> solution to that problem. It is a numerically unstable method for solving >> the problem. And computing the inverse actually requires solving a whole >> series of Ax=b problems. >> >> On Sat, Feb 8, 2025 at 1:51 AM Guenther Sohler via Discuss < >> discuss@lists.openscad.org> wrote: >> >>> In pythonscad there has been "divmatrix" next to multmatrix for a long >>> time and it exactly serves that purpose >>> >>> >>> >>> >>> On Sat, Feb 8, 2025 at 5:44 AM Sanjeev Prabhakar via Discuss < >>> discuss@lists.openscad.org> wrote: >>> >>>> I feel the inverse of a matrix should be part of the mathematical >>>> functions in stock openSCAD. >>>> >>>> That is not too difficult to do I suppose and makes the calculations >>>> related to linear algebra much simpler. >>>> >>>> I realised this while trying to calculate the intersection point >>>> between 2 straight lines, where 2 simple equations with 2 unknowns need to >>>> be calculated. >>>> >>>> It is possible to do such calculations by hand but would be much >>>> simpler if that can be part of the software algorithm. >>>> >>>> Thanks >>>> >>>> _______________________________________________ >>>> OpenSCAD mailing list >>>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > -- Null
P
pca006132
Sat, Feb 8, 2025 3:18 PM

See the answer in
https://math.stackexchange.com/questions/4297923/reasoning-behind-choosing-appropriate-decomposition-when-solving-linear-equation,
it is quite detailed.

Long story short: Computing the inverse is numerically unstable, there are
better approaches.

On Sat, Feb 8, 2025, 11:15 PM Guenther Sohler via Discuss <
discuss@lists.openscad.org> wrote:

I am Wondering after all, why you need Matrix Inversion in Openscad, when
there Is in numpy.

Am Samstag, 8. Februar 2025 schrieb Sanjeev Prabhakar via Discuss <
discuss@lists.openscad.org>:

I agree on speed but I am really wondering what has lead you to such a
conclusion about the accuracy.

Although I use 2 different ways to calculate intersections. Inverse
matrix method takes longer but the results are comparable with direct
calculation method by a derived formulae and it is much simpler to work
with, atleast in python.

I am not sure about openscad.

If there is any other method, which is better and faster, it will be
interesting to know.

On Sat, 8 Feb, 2025, 6:28 pm Adrian Mariano via Discuss, <
discuss@lists.openscad.org> wrote:

Sanjeev, you can calculate the inverse, sure, but if you are trying to
solve an equation like Ax=b you should NOT calculate the inverse and
compute inverse(A)*b because this is an inaccurate and slow way to get the
solution to that problem.  It is a numerically unstable method for solving
the problem.  And computing the inverse actually requires solving a whole
series of Ax=b problems.

On Sat, Feb 8, 2025 at 1:51 AM Guenther Sohler via Discuss <
discuss@lists.openscad.org> wrote:

In pythonscad there has been "divmatrix" next to multmatrix for  a long
time and it exactly serves that purpose

On Sat, Feb 8, 2025 at 5:44 AM Sanjeev Prabhakar via Discuss <
discuss@lists.openscad.org> wrote:

I feel the inverse of a matrix should be part of the mathematical
functions in stock openSCAD.

That is not too difficult to do I suppose and makes the calculations
related to linear algebra much simpler.

I realised this while trying to calculate the intersection point
between 2 straight lines, where 2 simple equations with 2 unknowns need to
be calculated.

It is possible to do such calculations by hand but would be much
simpler if that can be part of the software algorithm.

Thanks


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

--
Null


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

See the answer in https://math.stackexchange.com/questions/4297923/reasoning-behind-choosing-appropriate-decomposition-when-solving-linear-equation, it is quite detailed. Long story short: Computing the inverse is numerically unstable, there are better approaches. On Sat, Feb 8, 2025, 11:15 PM Guenther Sohler via Discuss < discuss@lists.openscad.org> wrote: > I am Wondering after all, why you need Matrix Inversion in Openscad, when > there Is in numpy. > > > Am Samstag, 8. Februar 2025 schrieb Sanjeev Prabhakar via Discuss < > discuss@lists.openscad.org>: > >> I agree on speed but I am really wondering what has lead you to such a >> conclusion about the accuracy. >> >> Although I use 2 different ways to calculate intersections. Inverse >> matrix method takes longer but the results are comparable with direct >> calculation method by a derived formulae and it is much simpler to work >> with, atleast in python. >> >> I am not sure about openscad. >> >> If there is any other method, which is better and faster, it will be >> interesting to know. >> >> >> On Sat, 8 Feb, 2025, 6:28 pm Adrian Mariano via Discuss, < >> discuss@lists.openscad.org> wrote: >> >>> Sanjeev, you can calculate the inverse, sure, but if you are trying to >>> solve an equation like Ax=b you should NOT calculate the inverse and >>> compute inverse(A)*b because this is an inaccurate and slow way to get the >>> solution to that problem. It is a numerically unstable method for solving >>> the problem. And computing the inverse actually requires solving a whole >>> series of Ax=b problems. >>> >>> On Sat, Feb 8, 2025 at 1:51 AM Guenther Sohler via Discuss < >>> discuss@lists.openscad.org> wrote: >>> >>>> In pythonscad there has been "divmatrix" next to multmatrix for a long >>>> time and it exactly serves that purpose >>>> >>>> >>>> >>>> >>>> On Sat, Feb 8, 2025 at 5:44 AM Sanjeev Prabhakar via Discuss < >>>> discuss@lists.openscad.org> wrote: >>>> >>>>> I feel the inverse of a matrix should be part of the mathematical >>>>> functions in stock openSCAD. >>>>> >>>>> That is not too difficult to do I suppose and makes the calculations >>>>> related to linear algebra much simpler. >>>>> >>>>> I realised this while trying to calculate the intersection point >>>>> between 2 straight lines, where 2 simple equations with 2 unknowns need to >>>>> be calculated. >>>>> >>>>> It is possible to do such calculations by hand but would be much >>>>> simpler if that can be part of the software algorithm. >>>>> >>>>> Thanks >>>>> >>>>> _______________________________________________ >>>>> OpenSCAD mailing list >>>>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>>>> >>>> _______________________________________________ >>>> OpenSCAD mailing list >>>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>> >> > > -- > Null > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
SP
Sanjeev Prabhakar
Sat, Feb 8, 2025 3:19 PM

Not for me, i thought this is trivial to do in openscad and can help
openscad community for the people who don't want to experiment with other
languages.

On Sat, 8 Feb, 2025, 8:45 pm Guenther Sohler via Discuss, <
discuss@lists.openscad.org> wrote:

I am Wondering after all, why you need Matrix Inversion in Openscad, when
there Is in numpy.

Am Samstag, 8. Februar 2025 schrieb Sanjeev Prabhakar via Discuss <
discuss@lists.openscad.org>:

I agree on speed but I am really wondering what has lead you to such a
conclusion about the accuracy.

Although I use 2 different ways to calculate intersections. Inverse
matrix method takes longer but the results are comparable with direct
calculation method by a derived formulae and it is much simpler to work
with, atleast in python.

I am not sure about openscad.

If there is any other method, which is better and faster, it will be
interesting to know.

On Sat, 8 Feb, 2025, 6:28 pm Adrian Mariano via Discuss, <
discuss@lists.openscad.org> wrote:

Sanjeev, you can calculate the inverse, sure, but if you are trying to
solve an equation like Ax=b you should NOT calculate the inverse and
compute inverse(A)*b because this is an inaccurate and slow way to get the
solution to that problem.  It is a numerically unstable method for solving
the problem.  And computing the inverse actually requires solving a whole
series of Ax=b problems.

On Sat, Feb 8, 2025 at 1:51 AM Guenther Sohler via Discuss <
discuss@lists.openscad.org> wrote:

In pythonscad there has been "divmatrix" next to multmatrix for  a long
time and it exactly serves that purpose

On Sat, Feb 8, 2025 at 5:44 AM Sanjeev Prabhakar via Discuss <
discuss@lists.openscad.org> wrote:

I feel the inverse of a matrix should be part of the mathematical
functions in stock openSCAD.

That is not too difficult to do I suppose and makes the calculations
related to linear algebra much simpler.

I realised this while trying to calculate the intersection point
between 2 straight lines, where 2 simple equations with 2 unknowns need to
be calculated.

It is possible to do such calculations by hand but would be much
simpler if that can be part of the software algorithm.

Thanks


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

--
Null


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Not for me, i thought this is trivial to do in openscad and can help openscad community for the people who don't want to experiment with other languages. On Sat, 8 Feb, 2025, 8:45 pm Guenther Sohler via Discuss, < discuss@lists.openscad.org> wrote: > I am Wondering after all, why you need Matrix Inversion in Openscad, when > there Is in numpy. > > > Am Samstag, 8. Februar 2025 schrieb Sanjeev Prabhakar via Discuss < > discuss@lists.openscad.org>: > >> I agree on speed but I am really wondering what has lead you to such a >> conclusion about the accuracy. >> >> Although I use 2 different ways to calculate intersections. Inverse >> matrix method takes longer but the results are comparable with direct >> calculation method by a derived formulae and it is much simpler to work >> with, atleast in python. >> >> I am not sure about openscad. >> >> If there is any other method, which is better and faster, it will be >> interesting to know. >> >> >> On Sat, 8 Feb, 2025, 6:28 pm Adrian Mariano via Discuss, < >> discuss@lists.openscad.org> wrote: >> >>> Sanjeev, you can calculate the inverse, sure, but if you are trying to >>> solve an equation like Ax=b you should NOT calculate the inverse and >>> compute inverse(A)*b because this is an inaccurate and slow way to get the >>> solution to that problem. It is a numerically unstable method for solving >>> the problem. And computing the inverse actually requires solving a whole >>> series of Ax=b problems. >>> >>> On Sat, Feb 8, 2025 at 1:51 AM Guenther Sohler via Discuss < >>> discuss@lists.openscad.org> wrote: >>> >>>> In pythonscad there has been "divmatrix" next to multmatrix for a long >>>> time and it exactly serves that purpose >>>> >>>> >>>> >>>> >>>> On Sat, Feb 8, 2025 at 5:44 AM Sanjeev Prabhakar via Discuss < >>>> discuss@lists.openscad.org> wrote: >>>> >>>>> I feel the inverse of a matrix should be part of the mathematical >>>>> functions in stock openSCAD. >>>>> >>>>> That is not too difficult to do I suppose and makes the calculations >>>>> related to linear algebra much simpler. >>>>> >>>>> I realised this while trying to calculate the intersection point >>>>> between 2 straight lines, where 2 simple equations with 2 unknowns need to >>>>> be calculated. >>>>> >>>>> It is possible to do such calculations by hand but would be much >>>>> simpler if that can be part of the software algorithm. >>>>> >>>>> Thanks >>>>> >>>>> _______________________________________________ >>>>> OpenSCAD mailing list >>>>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>>>> >>>> _______________________________________________ >>>> OpenSCAD mailing list >>>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>> >> > > -- > Null > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
AM
Adrian Mariano
Sat, Feb 8, 2025 3:21 PM

It is a well-known fact in numerical analysis that the inverse is
ill-conditioned and as a result the bounds on error when you use inverse
are bad.  The error is related to the condition number and the difference
may not be apparent or problematic for well-conditioned problems.

The MATLAB documentation has an example where the error is 1e-15 with LU
decomposition and 1e-6 with inverse.
https://www.mathworks.com/help/matlab/ref/inv.html

Three methods are commonly used for solving Ax=b that are stable and have
better error bounds than matrix inverse.  The most stable method is
eigenvalue decomposition (or SVD).  The other choices are QR factorization
and LU decomposition (aka Gaussian elimination).  The second two produce a
decomposition of A into a triangular matrix so that then the problem can be
solved by back-substitution.  I implemented QR factorization in OpenSCAD.
Note that eigenvalue/svd is very difficult to implement.  (I have written
an eigenvalue solver in OpenSCAD, but there doesn't seem to be a need for
this.)  But QR and LU factorization are simple methods that are easy to
code.

Note to Guenther:  I use pure OpenSCAD, so I need linear equation solutions
natively.

On Sat, Feb 8, 2025 at 10:04 AM Sanjeev Prabhakar sprabhakar2006@gmail.com
wrote:

I agree on speed but I am really wondering what has lead you to such a
conclusion about the accuracy.

Although I use 2 different ways to calculate intersections. Inverse matrix
method takes longer but the results are comparable with direct calculation
method by a derived formulae and it is much simpler to work with, atleast
in python.

I am not sure about openscad.

If there is any other method, which is better and faster, it will be
interesting to know.

On Sat, 8 Feb, 2025, 6:28 pm Adrian Mariano via Discuss, <
discuss@lists.openscad.org> wrote:

Sanjeev, you can calculate the inverse, sure, but if you are trying to
solve an equation like Ax=b you should NOT calculate the inverse and
compute inverse(A)*b because this is an inaccurate and slow way to get the
solution to that problem.  It is a numerically unstable method for solving
the problem.  And computing the inverse actually requires solving a whole
series of Ax=b problems.

On Sat, Feb 8, 2025 at 1:51 AM Guenther Sohler via Discuss <
discuss@lists.openscad.org> wrote:

In pythonscad there has been "divmatrix" next to multmatrix for  a long
time and it exactly serves that purpose

On Sat, Feb 8, 2025 at 5:44 AM Sanjeev Prabhakar via Discuss <
discuss@lists.openscad.org> wrote:

I feel the inverse of a matrix should be part of the mathematical
functions in stock openSCAD.

That is not too difficult to do I suppose and makes the calculations
related to linear algebra much simpler.

I realised this while trying to calculate the intersection point
between 2 straight lines, where 2 simple equations with 2 unknowns need to
be calculated.

It is possible to do such calculations by hand but would be much
simpler if that can be part of the software algorithm.

Thanks


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

It is a well-known fact in numerical analysis that the inverse is ill-conditioned and as a result the bounds on error when you use inverse are bad. The error is related to the condition number and the difference may not be apparent or problematic for well-conditioned problems. The MATLAB documentation has an example where the error is 1e-15 with LU decomposition and 1e-6 with inverse. https://www.mathworks.com/help/matlab/ref/inv.html Three methods are commonly used for solving Ax=b that are stable and have better error bounds than matrix inverse. The most stable method is eigenvalue decomposition (or SVD). The other choices are QR factorization and LU decomposition (aka Gaussian elimination). The second two produce a decomposition of A into a triangular matrix so that then the problem can be solved by back-substitution. I implemented QR factorization in OpenSCAD. Note that eigenvalue/svd is very difficult to implement. (I have written an eigenvalue solver in OpenSCAD, but there doesn't seem to be a need for this.) But QR and LU factorization are simple methods that are easy to code. Note to Guenther: I use pure OpenSCAD, so I need linear equation solutions natively. On Sat, Feb 8, 2025 at 10:04 AM Sanjeev Prabhakar <sprabhakar2006@gmail.com> wrote: > I agree on speed but I am really wondering what has lead you to such a > conclusion about the accuracy. > > Although I use 2 different ways to calculate intersections. Inverse matrix > method takes longer but the results are comparable with direct calculation > method by a derived formulae and it is much simpler to work with, atleast > in python. > > I am not sure about openscad. > > If there is any other method, which is better and faster, it will be > interesting to know. > > > On Sat, 8 Feb, 2025, 6:28 pm Adrian Mariano via Discuss, < > discuss@lists.openscad.org> wrote: > >> Sanjeev, you can calculate the inverse, sure, but if you are trying to >> solve an equation like Ax=b you should NOT calculate the inverse and >> compute inverse(A)*b because this is an inaccurate and slow way to get the >> solution to that problem. It is a numerically unstable method for solving >> the problem. And computing the inverse actually requires solving a whole >> series of Ax=b problems. >> >> On Sat, Feb 8, 2025 at 1:51 AM Guenther Sohler via Discuss < >> discuss@lists.openscad.org> wrote: >> >>> In pythonscad there has been "divmatrix" next to multmatrix for a long >>> time and it exactly serves that purpose >>> >>> >>> >>> >>> On Sat, Feb 8, 2025 at 5:44 AM Sanjeev Prabhakar via Discuss < >>> discuss@lists.openscad.org> wrote: >>> >>>> I feel the inverse of a matrix should be part of the mathematical >>>> functions in stock openSCAD. >>>> >>>> That is not too difficult to do I suppose and makes the calculations >>>> related to linear algebra much simpler. >>>> >>>> I realised this while trying to calculate the intersection point >>>> between 2 straight lines, where 2 simple equations with 2 unknowns need to >>>> be calculated. >>>> >>>> It is possible to do such calculations by hand but would be much >>>> simpler if that can be part of the software algorithm. >>>> >>>> Thanks >>>> >>>> _______________________________________________ >>>> OpenSCAD mailing list >>>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> >