The link below contains decent linear algebra functions in C language. I can not take credit for them. Charlie Matlack and "RobH45345" from the Arduino playground deserve the credit. As for the recursive covariance functions, I will handle that part - its working in Matlab, now it needs to be ported. I may do it Visual Basic or C. Anyway, the linear algebra functions below are a good start. I'm sure several of your customers will find them useful.
http://arduino.cc/playground/uploads/Co ... ixMath.zip
ANSI C Compatibility
-
- Posts: 163
- Joined: 24 March 2008, 23:33 PM
- Location: Southern California (Blue)
The code can't be used directly because it is implemented as part of a C++ class. The code generated from ZBasic source is C code and you can't instantiate C++ objects or invoke C++ methods directly from C (but see below for more information). One could add an intermediary module written in C++ that provides C-style entry points but that seems pointless in this case because there is absolutely no value added by encapsulating the matrix math functions in a C++ class other than the ability to use the Arduino Print object.liam.zbasic wrote:The link below contains decent linear algebra functions in C language. I can not take credit for them. Charlie Matlack and "RobH45345" from the Arduino playground deserve the credit.
I've created a new file, MatrixMath.c, that contains all of the functionality of MatrixMath.cpp except for MatrixPrint() and displaying a message when an error is encountered in matrix inversion. I modified the MatrixMath.h file to be compatible with both MatrixMath.c and MatrixMath.cpp.
The attached archive contains a ZBasic project matrix_test.pjt, a ZBasic source file matrix_test.bas and the MatrixMath.c and MatrixMath.h files described above. The test is a simple one that creates a matrix, transposes it and then displays the original and transposed matrix. The code is written in a general way to allow any rectangular ZBasic array to be used, irrespective of the lower bound. The code could be simplified if zero-based or one-based arrays were assumed.
An upcoming version of ZBasic will support directly accessing functions in C++ modules and classes. We're also working on the ability to import external procedures automatically from information in .h files.
- Attachments
-
- MatrixMath.zip
- (4.17 KiB) Downloaded 669 times
- Don Kinzer
-
- Posts: 163
- Joined: 24 March 2008, 23:33 PM
- Location: Southern California (Blue)
-
- Posts: 163
- Joined: 24 March 2008, 23:33 PM
- Location: Southern California (Blue)
What you observed is not a limitation of the IDE, of course, but a documented limitation of Fmt() based on the limits of the single precision (32-bit) floating point representation.liam.zbasic wrote:I modified your matrix display function to show more significant figures, but the IDE will not display more than 6 decimal places.
There has been discussion recently (among the maintainers of avr-gcc) of adding optional double precision (64-bit) floating point support in the avr-gcc compiler. If that is realized, we will probably add support for the Double data type in ZBasic as well.
- Don Kinzer
-
- Posts: 57
- Joined: 27 July 2009, 14:20 PM
- Location: Groningen, The Netherlands
- Contact:
Hello,
Just want to remark that the matrix transpose example works very well on my ZX-328nu too, and that I am very interested in further developments regarding the kalman filtering procedures. Furthermore, with these basic matrix algebra functions a wealth of applications becomes available, and with Don's announced ZBASIC support improvements it will become even more easy to include mathematical routines. I highly appreciate this
/Jurjen
Just want to remark that the matrix transpose example works very well on my ZX-328nu too, and that I am very interested in further developments regarding the kalman filtering procedures. Furthermore, with these basic matrix algebra functions a wealth of applications becomes available, and with Don's announced ZBASIC support improvements it will become even more easy to include mathematical routines. I highly appreciate this
/Jurjen
If you aren't using all of the matrix routines in your application, you might consider adding the line below to your .pjt file. The overall effect of this set of options, which are passed on to the back end compile and link phase, is to eliminate routines that are not referenced. With these options in place, the matrix_test code went from 10290 bytes to 7880 bytes when compiled for a ZX-24n.liam.zbasic wrote:All the matrix functions with 6x6 test matrices yield correct results.
Code: Select all
--gcc-opts=-ffunction-sections -fdata-sections -Wl,--gc-sections,--relax
- Don Kinzer