Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There are a few options. One is to use the piecewise command:

f=Piecewise([[(-10,1),sin(x)],[(1,10),cos(x)]],x)
plot(lambda x: f(x),(-2*pi,2*pi))

Another is to use a python function definition:

def f(x):
    if x<=1:
        return(sin(x))
    else:
        return(cos(x))
plot(f,(-2*pi,2*pi))

Note that with the python function definition, the plot command must be called just with f and not f(x). Calling with f(x) causes python to evaluate $f$ before doing the plot and will result in an incorrect plot.