# Defining a function and forcing max or min value Anonymous

Hi,

Is it possible to define a funtion, say f, and have it be the maximum (or minimum) of another function and a constant?

Example (pseudo-script): if g(x)=log(abs(x)), let f(x)=g(x) if g(x)>0, and f(x)=0 for all g(x)<0

Thanks N.C.

edit retag close merge delete

Sort by » oldest newest most voted

Is this what you want?

sage: g(x) = log(abs(x))
sage: f(x) = max_symbolic(g(x),0)
sage: f
x |--> max(log(abs(x)), 0)
sage: plot(f,(x,-e,e)) more

2

Cool! I didn't know that we'd actually implemented symbolic versions of max and min.

Yes, years ago - see http://trac.sagemath.org/sage_trac/ticket/6949. However, they have not been very well advertised! I'm going to edit the keywords to make this easier to find.

Yes, that's what I wanted to achieve. Thank you very much!

It also works with 2 functions, which is what I needed in the end.

Thanks again

f(x)=cos(x)

g(x)=sin(x)

h(x)=max_symbolic(f(x),g(x))

a=plot(f,-pi,pi)

b=plot(g,-pi,pi,color='green')

c=plot(h,-pi,pi,color='red')

show(a+b+c)

more