Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

plot issue with a self-defined piecewise function

The following code produces an error:

def f(x):
   if x>3:
       return(x^2)
   if x<=3:
       return(3*x)

plot(f(x),(x,0,5))

BUT, the code below works.

def f(x):
   if x>3:
       return(x^2)
   if x<=3:
       return(3*x)

plot(lambda x: f(x),(x,0,5))

So, my questions are: (1) why do you need the lambda function? and (2) when do you have to do this?