Jump to content

Recommended Posts

Posted

I have a formula :

 

(setq Formula1 (/ (* 0.046 (expt(* LenPath 78.0)(/ 1.0 2.0))) (expt SlopePath (/ 1.0 5.0))))

 

with two variables "LenPath" "SlopePath"

 

and I have 2 lists. Each item in the list represents

 

"LenPath" or "SlopePath"

 

So for example in my first list :

((setq LenList   '(2.1 4.0 6.8 10.0  12.0 16.0))

 

so the each item is "LenPath"

 

(setq SlopeList '(5.5 7.8 9.3 12.0  15.4 17.7))

 

each item is "SlopePath"

 

The new list generated would look something like:

(setq NewList '(0.418 0.538 0.678 0.781 0.814 0.914))

 

This is easy to do using mapcar and lambda if there is only one variable

However I stumped if there are two lists to use on one formula at the same time

 

Any ideas? thanks

Posted

Do you require perhaps something like this?

 

(mapcar
 (function
   (lambda ( _length _slope )
     (/ (* 0.046 (expt (* _length 78.0) 0.5)) (expt _slope 0.2))
   )
 )
 LenList
 SlopeList
)

 

I would definitely recommend you take a look at this tutorial :)

Posted

Thanks Lee

that works well. Yes I was having a look at it previously, but I could not work out from it how to use two variables at the same time. But it is a very useful tutorial - good work.

Posted
that works well. Yes I was having a look at it previously, but I could not work out from it how to use two variables at the same time. But it is a very useful tutorial - good work.

 

Thanks SmallFish - I found it quite difficult to write a tutorial to cater for developers of different levels of experience, whilst keeping the tutorial short and interesting.

 

Do you understand now the method I used above?

Posted (edited)

Maybe this will help with mapcar + lambda :

 

Make a couple simple lists


 (setq l1 '(2 3 4))
 (setq l2 '(2 4 )

 

Basic (mapcar) call:


 Add the atoms of the lists together

 (setq nl1 (mapcar '+ l1 l2))

 '(4 7 12)

 Multpily the atoms of the lists

 (setq nl2 (mapcar '* l1 l2))

 '(4 12 32)

 

Make an anonymous function (lambda)

: Find the length of the hypotonuse from the length of the 2 short sides

 


 (setq fun (lambda (a b) (sqrt (+ (* a a) (* b b)))))

 mapcar the (lambda) function to the lists

 (setq nl3 (mapcar 'fun l1 l2))

 '(2.82843 5 8.94427)

 

Include a (lambda) function in the (mapcar) call

: Divide the atoms in the lists as reals

 


  [b][color=BLACK]([/color][/b]setq nl4 [b][color=FUCHSIA]([/color][/b]mapcar '[b][color=NAVY]([/color][/b]lambda [b][color=MAROON]([/color][/b]a b[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]/ [b][color=GREEN]([/color][/b]float a[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]float b[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] l1 l2[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 '(1.0 0.75 0.5)

 

 

HTH -David

Edited by David Bethel
Posted

Thanks Lee

 

I need things simple to match my mind :)

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