Shared12 - Optimization Assignment / Optimization Notes.sagewsOpen in CoCalc
This material was developed by Aaron Tresham at the University of Hawaii at Hilo and is Creative Commons License
licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.


  • Intro to Sage
  • Graphing and Solving Equations
  • Differentiation


Optimization is the process of maximizing or minimizing a desired quantity given certain constraints.

For example, you may want to create a cylindrical can that holds 1 liter with the smallest possible surface area.

Our goal is to find an absolute max (or min) of some function. We know this will occur at a local max (min). To find these we want to find the critical points (places where the derivative is 0 or undefined). We then plug these critical points into the function to find the biggest (smallest) value.

The challenge of optimization is converting the statement of the problem (a paragraph) into the right equations, in order to define the quantity to maximize (or minimize) as a function of one variable, which allows us to take the derivative and find the critical points.

We will generally follow these steps:

Step 1 Define relevant variables.

Step 2 Draw a picture.

Step 3 Determine equations relating the variables.

Step 4 Use the given constraints to eliminate as many variables as possible in order to write the quantity to be maximized (or minimized) as a function of one variable.

Step 5 Take the derivative of our function.

Step 6 Set the derivative equal to 0 and solve for the variable. Find where the derivative is undefined (if any). These are the critical points.

Step 7 Plug the critical points and the endpoints of the domain into the function. [Note: If the endpoints of the domain are not included in the domain, then take limits instead.] The largest (smallest) value is the absolute max (min).

Step 8 Check your answer with a graph.

Step 9 Answer the original question. Sometimes you are asked for the max (or min) value. Other times you are asked for the values of the variables that result in that max (min) value. Sometimes you're asked for all of the above. When you're done with the other steps, go back and read the question. And don't forget to use correct units.

Example 1

A rectangle has perimeter 100 meters. Find the dimensions that maximize the area.


Step 1 Define variables: (1) the dimensions of the rectangle, which we'll call x and y ; (2) the area, which we'll call A ; and (3) the perimeter, which we'll call P .

Step 2 Draw a picture.

Step 3 Set up equations:

  • the area of a rectangle is A=xy .

  • the perimeter is P=2x+2y .

Step 4 Eliminate variables:

We are told that P=100 . Plug this in to the perimeter equation and solve for one of the variables:

%var y
[y == -x + 50]

We found y=-x+50 . Plug this into the area equation:


This equation gives A as a function of x :


Steps 5 and 6 Take the derivative and find the critical points.

\displaystyle -2 \, x + 50
[x == 25]

So A'(x)=0 if and only if x=25 .

Is the derivative ever undefined? No, except at the endpoints of the domain.

We need x and y to be positive (they are distances), which means they also need to be less than 50 (if one is greater than 50, the other would have to be less than 0 to get a perimeter of 100). So our endpoints are x=0 and x=50 .

Step 7 Plug the critical points into the function:

0 625 0

Now we see that 625 is the maximum possible area, which occurs when x=25 .

Step 8 Check with a graph.

We can see that A does indeed have a maximum value around x=25 .


Step 9 Answer the question:

When x=25 meters, y=-x+50=-25+50=25 meters as well.

So the rectangle with maximum area and perimeter 100 m is a 25 m by 25 m square.

Example 2

A landscape architect wishes to enclose a rectangular garden. On one side she will use a brick wall costing $30 per foot, and on the other three sides she will use a metal fence costing $10 per foot. If the area of the garden is to be 1000 square feet, find the dimensions of the garden that will minimize the cost of material.


Step 1 A =area of garden, C =cost of material, x =length, y =width (put brick along one of the " y " sides)

Step 2 Draw a picture.

Step 3


The cost of fence is the cost per foot times the distance for each side:


Step 4 We are told A=1000 , so plug this into the area equation and solve for y :



Now substitute for y in the cost equation to get a function of x :


Steps 5 and 6 Take the derivative and find the critical points.

\displaystyle -\frac{40000}{x^{2}} + 20
[x == -20*sqrt(5), x == 20*sqrt(5)]

Since x is a distance, we know x>0 , so we have one critical point: x=20\sqrt{5}\approx44.72 .

The domain of the cost function is (0,\infty) .

Step 7 Let's plug the critical point into the cost function:

800*sqrt(5) 1788.85438199983

What happens to the cost as x\rightarrow0 or x\rightarrow\infty ?

+Infinity +Infinity

As the x dimension gets really small or really large, the cost increases without bound, so we have a minimum at our critical point.

Step 8 Check with a graph.

We can see a minimum around x=45 .


Step 9 Make sure to answer the question: What dimensions minimize the cost?

We want x=20\sqrt{5}\approx 44.72 feet, and then \displaystyle y=\frac{1000}{x}=\frac{1000}{20\sqrt{5}}\approx 22.36 feet (remember the brick goes along one of the sides of this length).

Example 3

A box with no top is to be constructed from a 5 ft by 4 ft piece of cardboard by cutting a square from each corner and folding up the sides. How much should be cut off each corner to maximize the volume of the box?


Step 1 V= volume, l= length, w= width, and h= height. We'll cut out an h by h square from each side (when we fold up the sides, h will be the height of the box).

Step 2 Draw a picture.

Step 3 The volume of the box is V=lwh , where l=5-2h and w=4-2h .

Step 4 Substituting we see V=(5-2h)(4-2h)h=4h^3-18h^2+20h

%var h
4*h^3 - 18*h^2 + 20*h

Steps 5 and 6

V(h)=4*h^3 - 18*h^2 + 20*h
\displaystyle 12 \, h^{2} - 36 \, h + 20
[h == -1/6*sqrt(21) + 3/2, h == 1/6*sqrt(21) + 3/2]
N(-1/6*sqrt(21) + 3/2);N(1/6*sqrt(21) + 3/2)
0.736237384174027 2.26376261582597

Step 7

V(-1/6*sqrt(21) + 3/2);N(_)
-1/54*(sqrt(21) - 9)^3 - 1/2*(sqrt(21) - 9)^2 - 10/3*sqrt(21) + 30 6.56422554052121
V(1/6*sqrt(21) + 3/2);N(_)
1/54*(sqrt(21) + 9)^3 - 1/2*(sqrt(21) + 9)^2 + 10/3*sqrt(21) + 30 -0.564225540521207

The second value gives a negative volume, so that can't be right. It looks like the first value is the one we want.

We should also think about the endpoints of the domain. We need h>0 , since it is a length. We also need h<2 , because w=4-2h , and if h\ge2 , then w\le 0 .

Indeed, if we set h=0 or h=2 we get a volume of 0. This also explains why we got a negative volume for h\approx2.26 .

0 0

So the maximum volume is about 6.56 , which occurs when h\approx0.74 .

Step 8 On the graph, we can see a max around h\approx\frac{3}{4} .


Step 9 We should cut off approximately 0.74 feet from each corner.