First time here? Check out the FAQ!

Ask Your Question
1

Defining a function and forcing max or min value

asked 12 years ago

anonymous user

Anonymous

updated 12 years ago

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.

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
2

answered 12 years ago

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

Preview: (hide)
link

Comments

2

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

DSM gravatar imageDSM ( 12 years ago )

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 ( 12 years ago )
0

answered 12 years ago

sagemb gravatar image

updated 12 years ago

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)

Preview: (hide)
link

Comments

Glad it works for you!

kcrisman gravatar imagekcrisman ( 12 years ago )

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: 12 years ago

Seen: 2,736 times

Last updated: Apr 18 '12