The Buzzard Posted March 24, 2010 Share Posted March 24, 2010 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 Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted March 24, 2010 Author Share Posted March 24, 2010 Sorry, I think I explained myself incorrectly. What I meant was can each formula be written in one statement with the given arguments. Quote Link to comment Share on other sites More sharing options...
fixo Posted March 24, 2010 Share Posted March 24, 2010 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'~ Quote Link to comment Share on other sites More sharing options...
alanjt Posted March 24, 2010 Share Posted March 24, 2010 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 Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted March 24, 2010 Author Share Posted March 24, 2010 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. Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted March 24, 2010 Author Share Posted March 24, 2010 Thanks Alan, I think I can figure the rest from here. But what is apply in the statement for. Quote Link to comment Share on other sites More sharing options...
alanjt Posted March 24, 2010 Share Posted March 24, 2010 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 Quote Link to comment Share on other sites More sharing options...
alanjt Posted March 24, 2010 Share Posted March 24, 2010 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 (#) (* # #))) Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted March 24, 2010 Author Share Posted March 24, 2010 Alan, I looked up apply Function, Passes a list of arguments to, and executes, a specified function. Thanks Quote Link to comment Share on other sites More sharing options...
alanjt Posted March 24, 2010 Share Posted March 24, 2010 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 24, 2010 Share Posted March 24, 2010 Nice one Alan 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))))) Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted March 24, 2010 Author Share Posted March 24, 2010 I know, Its like putting 30lbs of s%#t in a 5lb bag. Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted March 24, 2010 Author Share Posted March 24, 2010 Now you tripped me up Lee, Whats with the condition? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 24, 2010 Share Posted March 24, 2010 Now you tripped me up Lee, Whats with the condition? Square roots of negative numbers don't exist in the Reals Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted March 24, 2010 Author Share Posted March 24, 2010 Square roots of negative numbers don't exist in the Reals But in that case, could'nt you just use abs in there someplace. Quote Link to comment Share on other sites More sharing options...
alanjt Posted March 24, 2010 Share Posted March 24, 2010 Nice one Alan 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 24, 2010 Share Posted March 24, 2010 But in that case, could'nt you just use abs in there someplace. But then you are changing the formula... :wink: Quote Link to comment Share on other sites More sharing options...
alanjt Posted March 24, 2010 Share Posted March 24, 2010 But then you are changing the formula... :wink: Ahh good point. Quote Link to comment Share on other sites More sharing options...
alanjt Posted March 24, 2010 Share Posted March 24, 2010 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))))) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 24, 2010 Share Posted March 24, 2010 One minor change to #2: Excellent spot - that would have you looking for days for that bug... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.