Ask Your Question
1

Defining a function and forcing max or min value

asked 2012-04-17 09:08:11 +0100

anonymous user

Anonymous

updated 2012-04-17 15:25:34 +0100

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 10:25:38 +0100

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 12:18:28 +0100 )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 15:25:12 +0100 )edit
0

answered 2012-04-18 05:39:09 +0100

sagemb gravatar image

updated 2012-04-18 05:42:11 +0100

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 09:56:19 +0100 )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 09:08:11 +0100

Seen: 2,697 times

Last updated: Apr 18 '12