Shop OBEX P1 Docs P2 Docs Learn Events
Inverse of a matrix — Parallax Forums

Inverse of a matrix

Spastic SamSpastic Sam Posts: 2
edited 2006-07-17 17:28 in BASIC Stamp
Hello,

I wish to take the inverse of a square matrix. Taking the inverse of a 2x2 or a 3x3 matrix is easy as one can use simple formulas of determinants to compute the invesre. I wish to take the inverse of larger matrices (4x4 and larger). This becomes much more difficult as one has to use methods such as the Gauss-Jordan elimination, Gaussian elimination, or LU decomposition. Having the·ability to perform·matrix operations such as this is important to me in selecting a microcontroller to work with. Are there any parallax products where the inverse of a matrix can be computed using a function keyword·in the software? (PBASIC or any other). Are there any plans to add·a matrix inverse function in the future?

Thanks

Spastic Sam.

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2006-06-27 19:21
    Well, the BS2 line of processors only has 32 bytes of memory, and run at 2000 to 10,000 PBasic Instructions per Second. So that would rule them out.

    To my knowledge, none of the Parallax processors would really be suitable for that kind of heavy number-crunching, they're more for low-level but very predictable processing -- like a robotics platform. Perhaps the SX or Propeller platforms COULD do that, but I don't think there's pre-built assembly for this.
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2006-06-27 20:14
    Even 'desktop' cpus do not have a single instruction for computing the inverse of a matrix, the determinates, Jacobian, etc...

    What is your application? Vision processing?

    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke
    Parallax Tech Support

    RClarke@Parallax.com
  • Spastic SamSpastic Sam Posts: 2
    edited 2006-06-27 20:37
    Hi Ryan,

    I guess I am spoiled with desktop programs like Matlab (or C++) that have a single instruction or function to compute the inverse of a matrix. My application is to perform linear-least squares fitting for a variety of applications including smooth motion planning through desired points, (auto-correlative) prediction of future positioning to minimize delays in image tracking.

    Thanks,

    Spastic Sam.
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2006-06-27 21:26
    Even in C++ it is not an instruction, but rather an object that has been created to do this...

    The SX may be able to compute this, but data storage/fetching will be an issue (due to the limited memory on a microcontroller)-
    The Propeller may be another avenue to consider- having a separate cog do the inversion- but again you need to facilitate the storage of the data...

    Sounds like an interesting application- please post updates as you go, would be interested in seeing how it goes...

    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke
    Parallax Tech Support

    RClarke@Parallax.com
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2006-06-27 22:00
    There was (is?) APL, a language based in a fundamental way on matrices and vectors.


    But I don't see any practical way to do it on the Stamp, for reasons of accuracy of integer calculations, memory, and speed. The Stamp is not meant for memory intensive math. The Propeller, maybe, with so much more memory, the larger integers and fixed point, and speed that might even include parallel processing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Fe2o3FishFe2o3Fish Posts: 170
    edited 2006-06-28 03:37
    Pardon my ignorance, but maybe an alternate method for computing least-squares would be
    in order due to the memory and speed constraints of the Parallax processors. Depending
    on the type of "linear" least-square fitting... if you're looking for something that will fit the
    general linear equation, y=mx+b, least-square fitting doesn't need n-order matricies to be
    calculated. Maybe the equations at the bottom of this webpage will help:

    www.shodor.org/UNChem/math/lls/index.html

    Depending on the number of data points and precision desired, you may have to be creative
    as to dealing with large numbers w.r.t. sums of squares and the like on a Basic Stamp.
    But the equations on the above webpage should be computable for relative small data
    sets on a Stamp2 or SX processor. You'll just hafta come "down" a layer of abstraction
    and get into more of the "dirt" of implementation smile.gif especially since the Basic Stamps
    don't do floating point.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Rusty-
    --
    Rusty Haddock = KD4WLZ = rusty@fe2o3.lonestar.org
    **Out yonder in the Van Alstyne (TX) Metropolitan Area**
    Microsoft is to software what McDonalds is to gourmet cooking
  • camtcamt Posts: 45
    edited 2006-07-14 15:21
    Further to Rusty's comments, you could use the uM-FPU floating point chip with the Stamp to do least-square line fitting.

    See the application note entitled "Application Note 3 - Calculating Trend Lines" located at:
    http://www.micromegacorp.com/appnotes.html

    It describes a least-square line fitting algorithm and a Basic Stamp example is included.

    Cam

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cam Thompson
    Micromega Corporation
  • achilles03achilles03 Posts: 247
    edited 2006-07-17 17:28
    Are you trying to implement a Kalman filter or something similar? A lot of recognition systems are using Kalman filters for this.

    Either way, you can compute the inverse of a matrix with the BS2, but you have to do it step-by-step. There's no single command that will do it. Even when Matlab does it, it's using several complex instructions on your CPU to compute the answer.

    You'll probably need more program memory than the base BS2 (maybe like the BS2e, sx, etc). The sx might be good as it's fast and got program memory. If you need more speed or memory, you might need to go to a PIC or Atmel or something. Just how fast is your sample rate?

    Dave
Sign In or Register to comment.