Author Topic: Matrix Mathmatics and LISP  (Read 4862 times)

0 Members and 1 Guest are viewing this topic.

Peter Jamtgaard

  • Guest
Matrix Mathmatics and LISP
« on: October 02, 2005, 11:13:42 AM »
Hello fellow swamp creatures...

Well I was interested in the average point thread and it got me wondering if any of you had developed a standardized set of functions for performing Matrix Mathmatics?

I have given this quite a bit of thought, but am interested in seeing if any of you have any of the matrix functions written. I have a file that includes most of them, but an interested in streamlining them, maybe starting a discussion of them.

Got Math?

Peter Jamtgaard P.E.

JohnK

  • Administrator
  • Seagull
  • Posts: 10646
Re: Matrix Mathmatics and LISP
« Reply #1 on: October 02, 2005, 11:20:37 AM »
Oho, that sounds like fun. I'm with ya on this endeavor.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Matrix Mathmatics and LISP
« Reply #2 on: October 02, 2005, 11:38:33 AM »
Post away!

 :lol:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

LE

  • Guest
Re: Matrix Mathmatics and LISP
« Reply #3 on: October 02, 2005, 12:05:35 PM »
Hello fellow swamp creatures...

Well I was interested in the average point thread and it got me wondering if any of you had developed a standardized set of functions for performing Matrix Mathematics?

I have given this quite a bit of thought, but am interested in seeing if any of you have any of the matrix functions written. I have a file that includes most of them, but an interested in streamlining them, maybe starting a discussion of them.

Got Math?

Peter Jamtgaard P.E.

There is a library made by Larry Leuallen and some help from John Udhen and Doug Broad was named: llmatrix.lsp, they went somehow the hard way, it must be still available by google...

Peter Jamtgaard

  • Guest
Re: Matrix Mathmatics and LISP
« Reply #4 on: October 02, 2005, 01:11:03 PM »
Here is a function that I just rewrote monitoring the point average thread.

Code: [Select]
(defun TransposeMatrix (lstMatrix)
 (if (car lstMatrix)
  (cons (mapcar 'car lstMatrix)
        (TransposeMatrix (mapcar 'cdr lstMatrix))
  )
 )
)

How about anyone wanting to comment on determinants? or have some better code for this?

Peter

Code: [Select]
; Determinant of Matrix

(defun Determinant (lstMatrix / sngReturn intRow intSign)
 (if debug (princ "\nDeterminant: "))
 (setq intRow 0
       intSign 1
       sngReturn 0.0
 )
 (if (> (length lstMatrix) 1)
  (if (= (length lstMatrix) 2)
   (setq sngReturn (- (* 1.0 (caar lstMatrix) (cadadr lstMatrix))
                      (* (cadar lstMatrix) (caadr lstMatrix))
                   )
   )
   (progn
    (repeat (length lstMatrix)
     (setq sngReturn (+ sngReturn
                        (* intSign
                           (determinant (getCofactorMatrix intRow 0 lstMatrix))
                           (car (nth intRow lstMatrix))
                        )
                     )
           intRow    (1+ intROw)
           intSign   (* -1 intSign)
     )
    )
   )
  )
  (setq sngReturn (caar lstMatrix))
 )
 sngReturn
)
; Get Cofactor Matrix
(defun GetCofactorMatrix
       (intRow intColumn lstMatrix / intCount lstMatrix2)
 (if debug (princ "\nGet Cofactor Matrix: "))
 (setq intCount 0)
 (foreach lstRow lstMatrix
  (if (/= intCount intRow)
   (setq lstMatrix2 (cons (cdr lstRow) lstMatrix2))
  )
  (setq intCount (1+ intCount))
 )
 (reverse lstMatrix2)
)


LE

  • Guest
Re: Matrix Mathmatics and LISP
« Reply #5 on: October 02, 2005, 01:48:52 PM »
Here I found the library I mentioned before:

http://www.google.com/search?hl=en&q=ll-matrix.lsp

Swift

  • Swamp Rat
  • Posts: 596
Re: Matrix Mathmatics and LISP
« Reply #6 on: October 03, 2005, 08:38:22 AM »
I use portions of the Template Numerical Toolkit in my c++ projects. It is open source and freely available from the National Institute of Standards and Technology.

Peter Jamtgaard

  • Guest
Re: Matrix Mathmatics and LISP
« Reply #7 on: October 03, 2005, 10:05:48 AM »

I downloaded the library you shared. Its determinant funtions appear to be limited to a 4x4 matrix. The one I shared above will do better than a 10x10. It takes a while though.

Do any of you have a function that will solve multiple simultaneous equations?

Peter


Here I found the library I mentioned before:

http://www.google.com/search?hl=en&q=ll-matrix.lsp

SMadsen

  • Guest
Re: Matrix Mathmatics and LISP
« Reply #8 on: October 03, 2005, 10:16:29 AM »
I once did a translation of some Graphic Gem matrix routines. While neither perfect nor complete in any way, I haven't missed any matrix routine since.

whdjr

  • Guest
Re: Matrix Mathmatics and LISP
« Reply #9 on: October 03, 2005, 10:27:12 AM »
Please for give my ignorance :oops: but what are matrixs used for and how or why would you use them?

Peter Jamtgaard

  • Guest
Re: Matrix Mathmatics and LISP
« Reply #10 on: October 03, 2005, 10:48:13 AM »
I matrix is a type of variable, generally a two dimensional array.

There are many engineering applications that use matrix mathmatics.

One type of matrix function is called a determinant. It can be used to solve simultaneous equations.

I used it to solve a complex set of equations called the three moments theorem which have to do with the distribution of weight of a continuous beam supported by multiple supports, with uneven span lengths. This is used in structural analysis of steel (or concrete) structures.

There are other situations where solving equations are used.

In VBA the matrix function library is not hard to get but in lisp it is more difficult.


1.0   0.0   0.0

0.0   1.0   0.0

0.0   0.0   1.0

is an example of a 3x3 matrix.

Peter