Ask Your Question

Revision history [back]

Concerning your second definition, as @paulmasson, i can not reproduce your problem.

Concerning you first definition, there is something tricky about symbolics to understand: when you write g(x) = max(f(x),0), the Python builtin max is used, which takes the max between two Python/Sage objects f(x) and 0, not pointwise! Since those two objects are not comparable, it considers that the first is to be returned, so max(f(x),0) is nothing but the object f(x). You can check by changing the order max(0,f(x)):

sage: g(x) = max(f(x),0)
sage: g
x |--> -2*x + 5
sage: g(x) = max(0,f(x))
sage: g
x |--> 0

So, you have to use is the "symbolic maximum", viewed as a mathematical function:

sage: g(x) = max_symbolic(f(x),0)
sage: g
x |--> max(-2*x + 5, 0)
sage: g.plot(-10,10)