Ask Your Question

how to find a local maximum?

asked 2012-04-15 08:37:12 -0500

Nil gravatar image

Hello. I'm fairly new to Sage, so lets see if someone more experienced can help!

Say I have a function f(x) continuous in [a,b] and derivable in (a,b). How can I implement in Sage a function 'maximum(f,a,b)' that returns the maximum of f(x) in [a,b] (as a numerical approximation, not as an expression)?

Thanks you a lot!

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2012-04-15 09:12:29 -0500

achrzesz gravatar image


edit flag offensive delete link more


However, this bit piece of code gives me a runtime error: f(x) = -4*x^6/(x^4 + 1)^(3/2) + 6*x^2/sqrt(x^4 + 1) find_maximum_on_interval(f,0,2) This is the error: RuntimeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined. Thanks you

Nil gravatar imageNil ( 2012-04-15 09:57:04 -0500 )edit

answered 2012-04-15 10:19:02 -0500

achrzesz gravatar image
sage: f = lambda x:-4*x^6/(x^4 + 1)^(3/2) + 6*x^2/sqrt(x^4 + 1)
sage: find_maximum_on_interval(f,0,2)
(2.8284271247461898, 1.0000000183339277)
edit flag offensive delete link more


Can you explain why, or how, does your solution work? Thanks you

Nil gravatar imageNil ( 2012-04-15 11:16:53 -0500 )edit

Read the documentation: sage: find_maximum_on_interval?? sage: find_minimum_on_interval?? and you will see that this procedure gives you an access to scipy.optimize.fminbound which uses Brent's method

achrzesz gravatar imageachrzesz ( 2012-04-15 19:46:33 -0500 )edit

More concretely, I was asking about the keyword lambda, because 'lambda?' yields no results.

Nil gravatar imageNil ( 2012-04-16 10:53:40 -0500 )edit

achrzesz gravatar imageachrzesz ( 2012-04-16 11:45:07 -0500 )edit

In Sage 7.3, the command is now find_local_maximum.

srobbert gravatar imagesrobbert ( 2016-10-05 13:45:25 -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

1 follower


Asked: 2012-04-15 08:37:12 -0500

Seen: 2,378 times

Last updated: Apr 15 '12