Calculus-Based Optimization: Finding Minima and Maxima using Maple, Study notes of Computer Science

A step-by-step guide on how to find the minimum and maximum values of a continuous function using maple. It covers both symbolic and numerical methods, with examples from calculus textbooks.

Typology: Study notes

Pre 2010

Uploaded on 08/18/2009

koofers-user-ljw
koofers-user-ljw 🇺🇸

10 documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
(1.1.1)(1.1.1)
(1.1.2)(1.1.2)
Chapter 12 Calculus based optimization -- finding minima and
maxima
Section 12.1 Finding minima and maxima by using Maple as a
calculus calculator
A standard topic in elementary calculus is how to find the minimum or maximum of a continuous
function in an interval (sometimes referred to as the local extrema of the function) through the use
of derivatives and a little algebra. The function that you are doing this to is sometimes referred to
as the objective function. Maple can be used to do the same calculations as you would do by hand
-- to find the extrema of the objective function, take its derivative with respect to x (using diff),
and then find where the derivative is equal to zero using solve or fsolve. The advantages of doing
it with a system such as Maple are the same as with other calculations: a) it is easier to do
correctly if the formula is involved or if you don't remember all the math, b) you can easily
organize the information about the problem and its solution using Maple documents so that it can
be easier to recall and presented, c) the speed of re-execution makes it easy to handle a bundle of
similar extrema problems.
Example 12.1.1 Finding the minimum and maximum using textually-specified commands
From Anton, Calculus 8th ed. p. 307 problem
13 (modified)
Find the absolute maximum and minimum
values of
f d x / 2
K
2$sin x for x in
K
π
4..π
Solution
f d x / 2
K
2$sin x
x/2
K
2 sin x
deriv ddiff f x ,x
K
2 cos x
plot f,
K
π
4..π
We define a continuous function
And compute its derivative symbolically.
We generate a plot to get an idea of where to
look for minima and maxima. Evidently the
minimum is in the interior of the interval
middle and the maximum is at the left.
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Calculus-Based Optimization: Finding Minima and Maxima using Maple and more Study notes Computer Science in PDF only on Docsity!

Chapter 12 Calculus based optimization -- finding minima and

maxima

Section 12.1 Finding minima and maxima by using Maple as a

calculus calculator

A standard topic in elementary calculus is how to find the minimum or maximum of a continuous function in an interval (sometimes referred to as the local extrema of the function ) through the use of derivatives and a little algebra. The function that you are doing this to is sometimes referred to as the objective function. Maple can be used to do the same calculations as you would do by hand -- to find the extrema of the objective function, take its derivative with respect to x (using diff ), and then find where the derivative is equal to zero using solve or fsolve. The advantages of doing it with a system such as Maple are the same as with other calculations: a) it is easier to do correctly if the formula is involved or if you don't remember all the math, b) you can easily organize the information about the problem and its solution using Maple documents so that it can be easier to recall and presented, c) the speed of re-execution makes it easy to handle a bundle of similar extrema problems.

Example 12.1.1 Finding the minimum and maximum using textually-specified commands

From Anton, Calculus 8th ed. p. 307 problem 13 (modified)

Find the absolute maximum and minimum values of

f d x / 2 K 2 $sin x for x in K

π 4

..π

Solution

f d x / 2 K 2 $sin x x / 2 K2 sin x deriv d diff f x , x K2 cos x

plot f ,K

π 4

..π

We define a continuous function

And compute its derivative symbolically.

We generate a plot to get an idea of where to look for minima and maxima. Evidently the minimum is in the interior of the interval middle and the maximum is at the left.

xmin d solve deriv = 0, x

1 2

π

f xmin

0

f K

π 4 2 C 2

f π

2

Finding where the derivative is zero should produce the minimum.

The minimum is confirmed to be zero -- the graph seems to indicate that but the picture doesn't let us know whether it's really zero or just really small.

Standard calculus procedure says to check out the value of the end points for the maximum. One is clearly larger than the other, and is bigger than the place within where the derivative is zero.

Thus we conclude that f attains a maximum at

x=K

π 4

. The value there is 2 C 2. The

minimum is zero, at x=

π 2

Example 12.1.1 Finding the minimum and maximum using textually-specified commands

Anton, Calculus, 8th ed. Problem 307

Section 12.2 One-step extrema finding using maximize and minimize

Maple also provides both exact and approximate numerical functions that do the entire sequence of steps needed to find extrema. In this section, we discuss the Maple functions that provide exact solutions to such problems.

The Maple function for finding maxima is, appropriately enough, called maximize. If expr is an expression involving a variable x , then maximize(expr,x=range) will produce maximum value of the expression for x in that range. If there is no maximum value, or if Maple can't find it, NULL is returned. Thus if maximize returns an answer, it should be "believable", but the absence of an answer doesn't meant that there is no answer. infinity or - infinity may be an answer if the function is unbounded within the range.

It is often a good idea when working on extrema problems to do a plot of the expression in question, so that you can some notion of where the maxima will be and what their values will be like.

Example 12.2.1 Finding the minimum and maximum using textually-specified commands

From Anton, Calculus 8th ed. p. 307 problem 13 (modified)

Find the absolute maximum and minimum values of

f d x / 2 K 2 $sin x for x in K

π 4

..π

Solution

f d x / 2 K 2 $sin x x / 2 K2 sin x

plot f ,K

π 4

..π

We define a function

We generate a plot to get an idea of where to look for minima and maxima. Evidently the minimum is in the middle and the maximum is at the left.

smallestValue d minimize f x , x =K

π 4

..π

0

largestValue d maximize f x , x =K

π 4

..π

2 C 2

The minimum is confirmed to be zero -- the graph seems to indicate that but the picture doesn't let us know whether it's really zero or just really small. Note again that this is the minimum value, it is not the location of the minimum value.

Finding the maximum is a copy/edit job once we've worked out how to do the minimum.

Sometimes, you want not only what the maximum or minimum value is, but also where it is. If you give maximize or minimize an extra third parameter, location, then it will return a sequence for a result. This sequence has a logical but somewhat intricate structure. You can use a chain of selections to extract the location var= location point from the answer given by Maple.

Example 12.2.2 Finding the minimum and maximum using textually-specified commands

From Anton, Calculus 8th ed. p. 307 problem 13 (modified)

Find the absolute maximum and minimum values of

maxResult d maximize f x , x =K

π 4

..π,

location

2 C 2 , x = K

π , 2 C 2

maxValue d maxResult 1 2 C 2 maxLocation d rhs maxResult 2 1 1 1

K

π

clickable interface.

Finding the maximum is a copy/edit job once we've worked out how to do the minimum.

If you want to evaluate another expression at a minimum point, then eval( expr , result[2][1][1]) will do that. This is because result[2] contains a set which describes the location/value pair. result[2][1] returns the first element of that, which is a list containing a particular location/value pair. result[2][1][1] is a set of the form { var = extreme value }. eval( expr , {var=value}) will evaluate expr with value replacing all occurrences of var in expr.

Example 12.2.3 Finding the minimum and maximum using textually-specified commands

From Anton, Calculus 8th ed. p. 316- Example 7

A liquid form of penicillin manufactured by a pharmaceutical firm is sold in bulk at a price of $200 per unit. If the total production cost (in dollars) for x units is

C x = 500000 C 80 $ x C 0.003$ x^2

and if the production capacity of the firm is at most 30,000 units in a specified time, how many units of penicillin must be manufactured and sold in that time to maximize the profit? What will the revenue be at the maximal profit?

Solution

C d x / 500000 C 80 $ x C 0.003$ x^2 x / 500000 C 80 x C0.003 x^2 R d x / 200 $ x x / 200 x

We define a Cost, Revenue, and Profit function, using the information given in the problem about cost, and the standard definitions from economics for revenue and profit.

P d x / R x K C x

x / R x K C x

plot P x , x = 0 ..

x

K 400000

K 200000

maxResult d maximize P x , x = 0 ..30000, location

7.00000 10^5 , x = 20000. ,

7.00000 10^5

maxLocation d floor rhs maxResult 2 1 1 1 20000

maxProfit d maxResult 1

$700,000.

revenueAtMax d R maxLocation

$4,000,000.

costAtMax d C maxLocation

$3,300,000.

We plot the profit function to scope out its behavior. Evidently the function does hit a maximum, roughly around x=20000. If we got x=35 as the answer from our maximum calculation in Maple, we would wonder if we did things correctly.

We are getting floating point answers from Maple because some of the numbers in C are floating point. If we wanted an exact calculation, we would change the .003 into 3/1000.

We learned from Example 12.2.2 how to get the location information information out. We use the floor function (see Chapter XX) to round down to the nearest integer, since we can't produce a fraction of a unit.

We used the clickable menu item "Numeric Formatting" to reformat the result in terms of currency.

L1 1 K L2 1 2 C L1 2 K L2 2 2

dist p1 , p

5 t^2 K 4 t C 1

plot dist p1 , p2 , t = 0 ..

t

plot dist p1, p2 , t = 0 ..

t

with Optimization

ImportMPS , Interactive , LPSolve , LSSolve , Maximize , Minimize , NLPSolve , QPSolve

minResult d Minimize dist p1 , p2 , t = 0 ..

0.447213595499958150, t = 0.

minLocation d minResult 2

t = 0.

ALocation d eval p1 , minLocation

0.400000000000000022,

BLocation d eval p2 , minLocation

behavior of the function near the minimum.

It's easy enough to use the visual feedback of the first plot to come up with the second plot range that's more suitable. In other words, we determined the new range 0..2 "by eyeball".

We load the entire Optimization package in....

so we can invoke the minimizer as Minimize rather than as Optimization [Minimize]. Note that the exact

location for t is 0.4, but that rounding error made during the operation of Minimize leads to only an approximation of the exact answer. This is typical.

According to the structure returned by this function, the location information is in the second element of the result.

We can find the location of particles A and B at t=0.4 by evaluating the expression p1 and p2 at that value of t. Note that minLocation is a list consisting of an equation, which eval can use as its second argument.

Section 13.Z Chapter summary

Table 13.Z.1 Minima and maxima

Operation Example

Exact minimum or maximum value f d x / 2 K 2 $sin x for x in K

π 4

..π

Solution

f d x / 2 K 2 $sin x x / 2 K2 sin x

plot f ,K

π 4

..π It's usually a good idea to plot the

objective function to get some sense of where the extrema are. Remember that the function to be investigated should be continuous if you expect good results from calculus techniques.

extremum point x^2 Csin x minEvalpt d minResult 2 1 1

x =

π

eval expr , minEvalpt 1 4

π

2 C 1

Approximate minimum or maximum value and location approxMinResult^ d^ Optimization Minimize^ f^ x^ ,^ x^ =

K

π 4

..π

0., x = 1.

approxMaxResult d Optimization Maximize f x , x =

K

π 4

..π

3.41421354582206549, x = K0. g rhs approxMaxResult 2 1 K1. eval expr , approxMaxResult 2 K0.