1 | initial version |
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)
2 | No.2 Revision |
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