Registered Member
|
Some background followed by my question....
Background: I have been a Matlab power user for a long time and very accustomed to the vector programming style which makes coding linear algebra very natural, simple and minimalistic. I implemented a Kalman filter in Matlab from scratch (did not use toolbox) for a basic IMU (inertial measurement unit), and wanted to do the same in the Arduino Due 32-bit microcontroller. But I dreaded this because Arduino's core programming language is C++ and frankly I dislike C++, fortran, etc. Then I discovered Eigen, and wow, it's almost as simple as Matlab and Octave. I'm very impressed by the simplicity - to the Eigen developers, thank you very much. My Kalman filter is working on the Arduino Due using Eigen 3.1.3. Question: I'm very happy and excited by the overloaded math operators for matrices. Addition, subtraction and multiplication are covered, but what about division? Is it possible to overload the "/" symbol? This would help streamline the Kalman filter matrix equations. Thank you. |
Moderator
|
One difficulty is that in C++ we can only overload operator/ . Therefore we can only express things like b/A <=> b * A.inverse() and not A\b <=> A.inverse() * b since in c++ \ is not an operator. Therefore I'm pretty sure such an operator would lead to a lot of confusion and errors. On the contrary, A.inverse() * b is not that verbose and very explicite. That said we still still have to "A.inverse() * b" fast such that it does not explicitly compute the inverse! That's a planed feature.
|
Registered Member
|
Doing something similar to A\b <=> A.inverse() * b would be very useful. Can you overload a different operator such as "~" (tilde) or "^" (hat)?
Or more specifically, "^" for division and "~" for transpose. Transpose is a very common matrix operation - it begs for its own operator. |
Moderator
|
That's way too confusing! Anyway, if you wanna play you can easily add your own shortcut:
http://eigen.tuxfamily.org/dox-devel/To ... Eigen.html If you want a fun but still readable shortcut for transpose (not tested, just to give the idea):
|
Registered Member
|
ggael ~ thanks for the tips. I'll try them out.
I certainly don't want to make matrix operations confusing. Just want to emulate what Matlab and Octave can do with inversion and transpose. They use the apostrophe (') for transpose. Since that is not a standard operator in C++, I suggested tilde (~). Question: why is the statement "static const T_t T;" a very polluting global variable? |
Moderator
|
This is because you cannot name any other variables or types with the letter "T". Except for local variables, it is thus not recommended at all to have too simple and common variable names. Still much better than a macro that would be named "T"!
|
Registered Member
|
To those interested in using Eigen on the Arduino 32-bit board called "Due", instructions posted here:
http://forum.arduino.cc/index.php?PHPSE ... msg1089371 |
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]