Jump to content

Function add/multiply lists


Kowal

Recommended Posts

Please help Lee Mac.

I need a arguments function that add/multiply the lists.

(setq (list (list a1 a2 a3 …) (list b1 b2 b3 …) (list c1 c2 c3 …) …))

(setq (list (list A1 A2 A3 …) (list B1 B2 B3 …) (list C1 C2 C3 …) …))

 

Algorithm:

List1  ‘((a1 a2) (b1 b2))

List2 ‘((A1 A2) (B1 B2) (C1 C2))

Result: ‘(( [a1*A1+a2*A2] [a1*B1+a2*B2] [a1*C1+a2*C2])
([b1*A1+b2*A2] [b1*B1+b2*B2] [b1*C1+b2*C2]))

 

Example 1

List1 ‘((1 2) (2 4))

List2 ‘((3 1) (2 2) (1 1))

Result:‘(( [1*3+2*1] [1*2+2*2] [1*1+2*1]) ([2*3+4*1] [2*2+4*2] [2*1+4*1]))

Result:‘((5 6 3) (10 12 6)) 

 

Example 2

List1 ‘((2  1 2) (3 1 1) (4 3 2))

List2 ‘((2 3 1) (1 1 1) (3 4 5))

Result: ‘((11 15 13) (10 14 9) (17 23 17))

Link to comment
Share on other sites

Is this a school assignment?

 

No, I'm an engineer.

I'm working on a Civil 3D.

Like Lisp macros, and I want to learn the argument function.

 

If this example is not difficult to ask for help.

Link to comment
Share on other sites

(defun f ( a b )
   (mapcar
       (function
           (lambda ( a )
               (mapcar
                   (function
                       (lambda ( b )
                           (apply '+ (mapcar '* a b))
                       )
                   )
                   b
               )
           )
       )
       a
   )
)

_$ (f '((1 2) (2 4)) '((3 1) (2 2) (1 1)))
((5 6 3) (10 12 6))

I believe the result for your second example is incorrect and should be:

_$ (f '((2 1 2) (3 1 1) (4 3 2)) '((2 3 1) (1 1 1) (3 4 5)))
((9 5 20) (10 5 18) (19 9 34))

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...