That worked, thank you. But I don't understand why the standard
notation has so many problems. What exactly is going wrong?
> > def h(x,n):
> > if x>2:
> > return n-x
> > else:
> > return n*x-2
This notation isn't very flexible though. For example, suppose I
wanted to plot h(-x,n) over the same range.
Can this be done without calling the symbolic engine? Is there a way
to bypass symbolic plots altogether?
Another approach that supplies default arguments for the *first*
variables is to use functools.partial:
def h(x,n):
if x>2:
return n-x
else:
return n*x-2
from functools import partial
plot(partial(h,1),(n,-1,1))
This effectively plots h(1,n), where n goes from -1 to 1.
Note that we can't do
plot(partial(h,x=1),(n,-1,1))
since plot calls the function by positional arguments, rather than
keyword arguments (i.e., this last plot calls h like this:
h(-.5434344,x=1), and so we get two values for x). I think this is a
bug; I think if the variable is specified in the plot range, the
function should be called with a keyword argument, so that the function
would be called as h(n=-.5434344,x=1). I believe I even have a patch
from late last year somewhere on my laptop that changes this behavior to
call a function using keyword arguments if the variable is specified in
the plot range. Once this bug is fixed, then doing plot(partial(h,x=1),
(n,-1,1)) would work.
Thanks,
Jason