|
From: Kris K. <kat...@gm...> - 2014-09-29 18:09:37
|
Hi Dimiter, On 09/29/2014 12:30 PM, Dimiter Prodanov wrote: > Hello, > > I define a function > > dy(y):=if y#0 and y#0.0 then 1/(2*y) else 'nan; > > Then I wanted to substitute it's first argument by a value. The idea is > to use pass a function having a variable number of arguments as a method > parameter and then to evaluate it only on certain arguments. > > > I stumbled on the following weird behavior: > > apply(dy, [y=0]); > expt: undefined: 0 to a negative exponent. > -- an error. > The list given to apply shouldn't include the parameter name; what's happening is that the equation "y=0" is getting passed to dy and that's causing the problem. (%i3) trace(dy)$ (%i4) apply(dy,[y=0]); 1 Enter dy [y = 0] expt: undefined: 0 to a negative exponent. #0: A traced function(y=y = 0) -- an error. To debug this try: debugmode(true); (%i5) apply(dy,[0]); 1 Enter dy [0] 1 Exit dy nan (%o5) nan > also here > > at(dy(y),[y=0]); > > expt: undefined: 0 to a negative exponent. > -- an error. > Here the problem is that dy(y) is evaluated before the y=0 is done. (%i6) at(dy(y),[y=0]); 1 Enter dy [y] 1 Exit dy 1/(2*y) expt: undefined: 0 to a negative exponent. -- an error. To debug this try: debugmode(true); I hope this helps. Cheers, Kris Katterjohn |