RE: find out the max ormin of a function
- To: mathgroup at smc.vnet.net
- Subject: [mg41363] RE: [mg41334] find out the max ormin of a function
- From: "David Park" <djmp at earthlink.net>
- Date: Fri, 16 May 2003 06:42:50 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Sabrina, In making plots I always like to load the following package so I can use the color names directly. Needs["Graphics`Colors`"] Now define your function... f[x_] := x^2 + 2x + 1 Solve for where the slope is zero and save the solution, which is in the form of replacement rules. (Much better than actually setting x to some value.) xsol = Solve[f'[x] == 0] {{x -> -1}} Now let's plot the function and the minimum point. We use xsol, the replacement rule, to substitute the actual value of x to obtain the point. Plot[f[x], {x, -2, 2}, Epilog -> {Red, AbsolutePointSize[5], Point[{x, f[x]}] /. xsol}]; Of course, when you are looking for the minimum or maximum in a closed interval, you also have to consider the case where f'[x] is not zero in the interval, and so the minimum and maximum will be at the endpoints of the interval. David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: sabrina [mailto:hxs61 at po.cwru.edu] To: mathgroup at smc.vnet.net 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? Thanks a lot Sabrina