Ask Your Question

Revision history [back]

Could be how you're plotting the function. This works for me:

f(x) = 5 - 2*x
def g(x):
    return f(x) if f(x)>0 else 0
plot(g,x,-10,10)

With a slight modification to your first solution, this also works:

f(x) = 5 - 2*x
def g(x):
    return max(f(x),0)
plot(g,x,-10,10)

Could be how you're plotting the function. This works for me:

f(x) = 5 - 2*x
def g(x):
    return f(x) if f(x)>0 else 0
plot(g,x,-10,10)

With a slight modification to your first solution, this also works:

f(x) = 5 - 2*x
def g(x):
    return max(f(x),0)
plot(g,x,-10,10)

EDIT: Your plotting issues are a result of what Sage documentation calls "accidental evaluation". See item (4) on this page: http://doc.sagemath.org/html/en/tutorial/tour_functions.html