Re: find out the max ormin of a function
- To: mathgroup at smc.vnet.net
- Subject: [mg41371] Re: find out the max ormin of a function
- From: Bill Rowe <listuser at earthlink.net>
- Date: Fri, 16 May 2003 06:45:31 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On 5/15/03 at 3:58 AM, hxs61 at po.cwru.edu (sabrina) wrote: >Hi, all: I just started to learn Mathematica: I have one function like >this: y=x^2+2x+1 How can I find the minimum of this funtion in a range >of [-2, 2]? Or put it in a simple way: if I know y'=2x+2, how can I >use Mathematica to find the minimam? There are a number of ways this can be done. First, there is sol = Solve[D[x^2 + 2 x +1,x]==0,x] x^2 + 2 x + 1/.sol Which shows a minium of 0 at x = -1 Alternatively, there is FindMinimum[x^2 + 2 x + 1, {x, -2, 2}] or there is the package NumericalMath`NMinimize` Notice, the result returned by FindMinimum for a quadratic equation like this will be the one global minimum. If you wanted the minimum of this equation on an interval that does not contain the global minimum you would need to do a bit more work than what I've shown here to use FindMinimum. The functions in NMinimize handle this case for you in a more intuitive way IMO. For polynomials of one variable, taking the derivative and solving for all of the zeros is probably just about the best choice. Using this approach, you can find both the maxima and minima at the same time. FindMinimum can easily find a maximum by simply multiplying the expression to be maximized by -1. For complex oscillatory functions or multidimensionsal problems it is you will want to use FindMinimum or better the functions in NMinimize.