D
D
Dmitry Opalev @Dmitry2018-03-31 20:06:30
JavaScript
Dmitry Opalev @Dmitry, 2018-03-31 20:06:30

Why does JS calculate inaccurately?

I found a script for calculating the determinant of a matrix: http://mathhelpplanet.com/static.php...nad-matritsami
We need to calculate the determinant of such a matrix:
VZ56kDva7bo.jpg

var M = new Array();
M[0] = new Array(-2.3128860264714093, -1.1564430132357046, 0, 254.417462911855);
M[1] = new Array(-1.1564430132357046, -2.3128860264714097, 254.417462911855, -9.769962616701378*Math.pow(0.1,14));
M[2] = new Array(10.876222279050648, -5.572421139525324, 59.09640000000007, -3559.6051520867136);
M[3] = new Array(-5.572421139525324, 10.876222279050648, -3559.6051520867136, 59.09640000000007);

At the same time, the JS script returns -0, and the matcad returns a specific number:
SsCyf8IIJEU.jpg
Moreover, if 10^(-14) is removed from element 2 of row 4 of the column, then the results can be said to be the same:
36AtzETVMX4.jpg
What is the problem and how to solve it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Olohtonov, 2018-03-31
@sgjurano

This is called numerical instability, one of the most common problems in computing.
The solution is to use ready-made linear algebra libraries, where people have already solved these problems for you.

A
Andrew, 2018-03-31
@KickeRockK

Here
Good about rounding and precision in JS.
I see the solution in using MatLab. :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question