Ask Your Question
1

Defining a function and forcing max or min value

asked 2012-04-17 02:08:11 -0500

anonymous user

Anonymous

updated 2012-04-17 08:25:34 -0500

kcrisman gravatar image

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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2012-04-17 03:25:38 -0500

kcrisman gravatar image

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))

image description

edit flag offensive delete link more

Comments

2

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

DSM gravatar imageDSM ( 2012-04-17 05:18:28 -0500 )edit

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.

kcrisman gravatar imagekcrisman ( 2012-04-17 08:25:12 -0500 )edit
0

answered 2012-04-17 22:39:09 -0500

sagemb gravatar image

updated 2012-04-17 22:42:11 -0500

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)

edit flag offensive delete link more

Comments

Glad it works for you!

kcrisman gravatar imagekcrisman ( 2012-04-18 02:56:19 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-04-17 02:08:11 -0500

Seen: 979 times

Last updated: Apr 17 '12