Matrix : create, read, write

Matrix : create, read, write

Anonymous
Not applicable
1,300 Views
5 Replies
Message 1 of 6

Matrix : create, read, write

Anonymous
Not applicable

Hello everyone,

 

I'm a full beginner in AutoLISP, having a big issue with matrix. Impossible to find clear help, so I require your advices.

 

I succeded to create a matrix of 3 dimenssions, (almost) succeeded to read an element... but impossible to write one element.

Have you succeedded or found something about this issue ? If not, how to skirt the problem ?

 

Below are my code to create a matric l x c x p containing the element a :

(defun ctab3 (a l c p / lin col pro)
 (repeat l (setq lin (cons a lin)))
 (repeat c (setq col (cons lin col)))
 (repeat p (setq pro (cons col pro)))
)

And there to search an element in lst (matrix l x c x p) at the rank l-c-p (but the transfer of the list doesn't work) :

(defun stab3 (lst p c l)
 (nth l-1 (nth c-1 (nth p-1 lst)))
)  

 

0 Likes
1,301 Views
5 Replies
Replies (5)
Message 2 of 6

stevor
Collaborator
Collaborator
Perhaps you should show a few examples of your arrays with their elements in columnar form.
S
0 Likes
Message 3 of 6

scot-65
Advisor
Advisor
What you are showing in the first code quote panel are three LISTs.
In other words, three one-dimensional arrays.
To make it into a two dimensional array (matrix) is to
bundle these three lists into a single list:

(list
(repeat l...
(repeat c...
(repeat p...
);list

A pseudo 3-dimensional list can be described as follows:
(list
(cons a (list b c d))
(cons e (list f g h))
);list
This works well when reading a INI-structured external file
where a (and e) is the [Header] inside the INI file.

First Dimension: Left and Right.
Second Dimension: Up and Down.
Third dimension: Towards and Away.
Fourth Dimension: Array or List inside any one of these nuggets.
...

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 4 of 6

shoukat
Explorer
Explorer

(defun stab3 (lst p c l) (nth (- l 1) (nth (- c 1) (nth (- p 1) lst))) )

0 Likes
Message 5 of 6

martti.halminen
Collaborator
Collaborator

You have hit one of the weak points of AutoLISP: unlike most programming languages, it doesn't have a native array datatype, and rather poor tools for building your own.

 

I see three possible ways to do this:

 

A) Building this on top of AutoLISP lists. This is made somewhat clumsy by the limitation that in AutoLISP (unlike other Lisp implementations) lists are essentially read-only once created: the only way to change one is to copy it, changing some items in the copying.

 

B) Using ActiveX safearrays, see the vlax-make-safearray and vlax-safearray-... functions.

 

C) Doing this part of your program in some other language. For example I am maintaining a large AutoLISP program where any parts needing a more capable language are implemented in Common Lisp.

 

-- 

 

0 Likes
Message 6 of 6

hgasty1001
Advisor
Advisor

Hi,

 

Just a simplistic approach:

 

(setq matrix (list (list a11 a12 a13) (list a21 a22 a3) (list a31 a32 a33)))

 

(defun aij(m i j)

 (nth (- i 1) (nth (- j 1) m))

)

 

(defun DotProduct (v1 v2)

(apply '+ (mapcar '* v1 v2))

)

 

And so on...

 

If you need a really good start on matrix algebra with Autolisp, you can visit: http://www.lee-mac.com/mathematicalfunctions.html#matrixvector

 

Gaston Nunez

 

 

 

0 Likes