Jump to content
The Buzzard

Arguments

Recommended Posts

The Buzzard

Hello to all,

 

Attached below are three formulas to solve for distance for ellipsodial heads of different types.

My question is can each formula be written in one argument or does it need to be written in several?

I am not completely sure how to break this down. Any help on this would be greatly appreciated.

 

Again Thank You in advance,

The Buzzard

IDD2.jpg

Share this post


Link to post
Share on other sites
The Buzzard

Sorry,

 

I think I explained myself incorrectly.

What I meant was can each formula be written in one statement with the given arguments.

Share this post


Link to post
Share on other sites
fixo
Sorry,

 

I think I explained myself incorrectly.

What I meant was can each formula be written in one statement with the given arguments.

Not sure about but have you tried use the COND statement?

 

~'J'~

Share this post


Link to post
Share on other sites
alanjt

I probably overlooked something, but this should be a good example (your first function)...

 

(defun foo (L r O D tt / _sq)
 (setq _sq (lambda (#) (* # #)))

 (- L (sqrt (- (_sq (- L r)) (_sq (/ (* O D) (apply '- (list 2 tt r)))))))
) ;_ defun

Share this post


Link to post
Share on other sites
The Buzzard

Sorry again,

 

Fixo,

 

I do not mean to combine all three or a way to pick a formula.

For each formula above can the supplied arguments be put into one continuous statement for each formula.

Share this post


Link to post
Share on other sites
The Buzzard

Thanks Alan,

 

I think I can figure the rest from here.

But what is apply in the statement for.

Share this post


Link to post
Share on other sites
alanjt
Thanks Alan,

 

I think I can figure the rest from here.

But what is apply in the statement for.

 

It was to subtract the 3 numbers, but I completely forgot you can add more than 2 numbers to the (- function.

 

(defun foo (L r O D tt / _sq)
 (setq _sq (lambda (#) (* # #)))

 (- L (sqrt (- (_sq (- L r)) (_sq (/ (* O D) (- 2 tt r))))))
) ;_ defun

Share this post


Link to post
Share on other sites
alanjt

You don't have to use the _sq sub function. However, it saves you a lot of typing and condenses your routine quite a bit.

 

(setq _sq (lambda (#) (* # #)))

Share this post


Link to post
Share on other sites
The Buzzard

Alan,

 

I looked up apply Function,

 

Passes a list of arguments to, and executes, a specified function.

 

Thanks

Share this post


Link to post
Share on other sites
alanjt
Alan,

 

I looked up apply Function,

 

Passes a list of arguments to, and executes, a specified function.

 

Thanks

 

Hope it helps.:)

And good luck keeping your head on straight while typing everything out. :wacko:

Share this post


Link to post
Share on other sites
Lee Mac

Nice one Alan :thumbsup:

 

This is the only improvement I can see:

 

(defun foo (L r O D tt / _sq n)
 (setq _sq (lambda (#) (* # #)))

 (cond (  (minusp (setq n (- (_sq (- L r)) (_sq (/ (* O D) (- 2 tt r)))))) nil)

       (  (- L (sqrt n)))))

Share this post


Link to post
Share on other sites
The Buzzard

I know,

 

Its like putting 30lbs of s%#t in a 5lb bag.

Share this post


Link to post
Share on other sites
The Buzzard

Now you tripped me up Lee,

 

Whats with the condition?

Share this post


Link to post
Share on other sites
Lee Mac
Now you tripped me up Lee,

 

Whats with the condition?

 

Square roots of negative numbers don't exist in the Reals :)

Share this post


Link to post
Share on other sites
The Buzzard
Square roots of negative numbers don't exist in the Reals :)

But in that case, could'nt you just use abs in there someplace.

Share this post


Link to post
Share on other sites
alanjt
Nice one Alan :thumbsup:

 

This is the only improvement I can see:

 

(defun foo (L r O D tt / _sq n)
 (setq _sq (lambda (#) (* # #)))

 (cond (  (minusp (setq n (- (_sq (- L r)) (_sq (/ (* O D) (- 2 tt r)))))) nil)

       (  (- L (sqrt n)))))

 

HaHa

I guess we can't have i. Good catch.

Share this post


Link to post
Share on other sites
Lee Mac
But in that case, could'nt you just use abs in there someplace.

 

But then you are changing the formula... :wink:

Share this post


Link to post
Share on other sites
alanjt
But then you are changing the formula... :wink:

 

Ahh good point.:oops:

Share this post


Link to post
Share on other sites
alanjt

One minor change to #2:

 

(defun foo (L r O D tt / _sq n)
 (setq _sq (lambda (#) (* # #)))

 (cond (  (minusp (setq n (- (_sq (- L r)) (_sq (/ (* O D) (- 2. tt r)))))) nil)

       (  (- L (sqrt n)))))

Share this post


Link to post
Share on other sites
Lee Mac
One minor change to #2:

 

Excellent spot - that would have you looking for days for that bug... :cry:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×