Math.net check if two matrices are almost equal?

96 views Asked by At

Libraries like numpy for python make it really simple to check whether two matrices are almost equal (numpy.allclose/numpy.isclose). I couldn't find anything similar for math.net. How would I check that two matrices are equal up to a tolerance in math.net?

1

There are 1 answers

0
emilaz On BEST ANSWER

Ok I found it, MathNet.Numerics.Precision includes what I was looking for. Works for vectors, matrices, and a whole lot of other data types. Can be used as follows

using MathNet.Numerics

var foo =  CreateMatrix.DenseIdentity<double>(3);
var bar =  CreateMatrix.DenseIdentity<double>(3);
var tolerance = 1e-5;
Precision.AlmostEqual(foo, bar, tolerance);
// or even simpler...
foo.AlmostEqual(bar, tolerance);

Not sure why I missed it at my first google attempts, but in case anyone else is struggling with this I'm keeping this up.