tomstewart89 / BasicLinearAlgebra

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

problem on Invert matrix<1, 1> #66

Closed YuriSizuku closed 1 year ago

YuriSizuku commented 1 year ago

Here is the example.


BLA::Matrix<1, 3> H; 
BLA::Matrix<3, 3> P; 
auto C = BLA::Invert(H*P*(~H));

And error occurs no instance of overloaded function "BLA::Invert" matches the argument list argument types are: (BLA::Matrix<1, 1, float>)

It will be nice to implement this trivial situation.

tomstewart89 commented 1 year ago

Hey @YuriSizuku , thanks for your feedback!

The problem is that the Invert function modifies the input matrix in-place so it expects an lvalue reference whereas the result of the operation H*P*(~H) is an rvalue. lvalues / rvalues are a bit tricky, you can read about them here if you're not already familiar with them.

You can fix this problem by setting the result of H*P*(~H) to a variable like so:

auto C = H*P*(~H);
bool success = BLA::Invert(C);

Or by using the Inverse function instead:

auto C = BLA::Inverse(H*P*(~H));

Hope that helps!

YuriSizuku commented 1 year ago

Thank you very much. Now I understand the difference of Invert and Inverse. I followed this example HowToUse.ino. I think it will be very helpful to add some documents or comments to show the difference of this two function.

tomstewart89 commented 1 year ago

Fair enough, in general I think the documentation for this library could be improved, but for now I added a bit more detail to HowToUse.ino.

Hope that helps!