tomstewart89 / BasicLinearAlgebra

A library for using matrices and linear algebra on Arduino
MIT License
185 stars 38 forks source link

Invert appears to return improper results when using a double Array #41

Closed NWalker4483 closed 2 years ago

NWalker4483 commented 2 years ago

I'm using a teensy 4.1 and the following code.

Matrix<6, 6, Array<6, 6, double>> motor_reductions = {
  1. / 48., 0, 0,         0, 0, 0,
  0, 1. / 48., 0,         0, 0, 0,
  0, -1. / 48., 1. / 48., 0, 0, 0,
  0, 0, 0,                 1. / 24., 0, 0,
  0, 0, 0,                -1. / 28.8, 1. / 28.8, 0,
  0, 0, 0,                -1. / 12., 1. / 24., 1. / 24.
};

Matrix<6, 6,Array<6,6,double>> degrees_per_step;
Matrix<6, 6,Array<6,6,double>> degrees_per_step_inv;

void setup(){
degrees_per_step = motor_reductions * ((360. / (double)SPR);
Invert(degrees_per_step, degrees_per_step_inv);
}
// degrees_per_step_inv(0,0) == 26.6666660308837891;
// When it should equal
// degrees_per_step_inv(0,0) == 26.666666666666668L;
tomstewart89 commented 2 years ago

Hey @NWalker4483,

Thanks for the info, you're right there was a bug in the way I was declaring some intermediate variables in the invert functions. I just released an update (containing this commit) which should fix the problem. If you update to version 3.3 then the element in that inverse should equal 80 / 3 up to double precision (at least on arduinos that support 64-bit floats anyway).

I'll close this issue but if you have any more trouble feel free to re-open it!