Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
ANSI C Compatibility
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Forum Index -> ZBasic Native Mode
Author Message
liam.zbasic



Joined: 25 Mar 2008
Posts: 163
Location: Southern California (Blue)

Posted: 25 January 2012, 22:32 PM    Post subject: Reply with quote

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/Code/MatrixMath.zip
Back to top
liam.zbasic



Joined: 25 Mar 2008
Posts: 163
Location: Southern California (Blue)

Posted: 26 January 2012, 0:26 AM    Post subject: Reply with quote

If you have a simple matrix add example showcasing passing arrays between Zbasic and C, that'll help tremendously. Thanks.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR

Posted: 26 January 2012, 1:27 AM    Post subject: Reply with quote

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.
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.

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.



MatrixMath.zip
 Description:

Download
 Filename:  MatrixMath.zip
 Filesize:  4.17 KB
 Downloaded:  128 Time(s)

Back to top
liam.zbasic



Joined: 25 Mar 2008
Posts: 163
Location: Southern California (Blue)

Posted: 26 January 2012, 4:28 AM    Post subject: Reply with quote

Excellent! I will give it a shot. Thank you very much.
Back to top
liam.zbasic



Joined: 25 Mar 2008
Posts: 163
Location: Southern California (Blue)

Posted: 26 January 2012, 8:40 AM    Post subject: Reply with quote

All the matrix functions with 6x6 test matrices yield correct results. Question... I modified your matrix display function to show more significant figures, but the IDE will not display more than 6 decimal places. Is that the limit for single type variables?
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR

Posted: 26 January 2012, 15:13 PM    Post subject: Reply with quote

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.
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.

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.
Back to top
kranenborg



Joined: 27 Jul 2009
Posts: 38
Location: Uppsala, Sweden

Posted: 26 January 2012, 23:21 PM    Post subject: Reply with quote

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
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR

Posted: 27 January 2012, 0:41 AM    Post subject: Reply with quote

liam.zbasic wrote:
All the matrix functions with 6x6 test matrices yield correct results.
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.
Code:
--gcc-opts=-ffunction-sections -fdata-sections -Wl,--gc-sections,--relax

The v3.4.x version of the compiler (currently being tested) includes these options by default for the back end compiler/linker in the build script.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Native Mode Time synchro. with the server - Timezone/DST with your computer
Goto page Previous  1, 2
Page 2 of 2

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group