CoCalc Public FilesMisc Stuff / 12 - Optimization Assignment / Optimization Notes.sagewsOpen with one click!
Author: Aaron Tresham
Views : 115
Compute Environment: Ubuntu 18.04 (Deprecated)
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 xx and yy; (2) the area, which we'll call AA; and (3) the perimeter, which we'll call PP.

Step 2 Draw a picture.

Step 3 Set up equations:

  • the area of a rectangle is A=xyA=xy.

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

Step 4 Eliminate variables:

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

%var y solve(100==2*x+2*y,y)
[y == -x + 50]

We found y=x+50y=-x+50. Plug this into the area equation: A=xy=x(x+50)=x2+50xA=xy=x(-x+50)=-x^2+50x

This equation gives AA as a function of xx: A(x)=x2+50xA(x)=-x^2+50x

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

A(x)=-x^2+50*x dA(x)=derivative(A,x);show(dA(x)) solve(dA(x)==0,x)
2x+50\displaystyle -2 \, x + 50
[x == 25]

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

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

We need xx and yy 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=0x=0 and x=50x=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=25x=25.

Step 8 Check with a graph.

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


Step 9 Answer the question:

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

So the rectangle with maximum area and perimeter 100100 m is a 2525 m by 2525 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 AA=area of garden, CC=cost of material, xx=length, yy=width (put brick along one of the "yy" sides)

Step 2 Draw a picture.

Step 3 A=xyA=xy

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


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



Now substitute for yy in the cost equation to get a function of xx:


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

C(x)=40000/x+20*x dC(x)=derivative(C,x);show(dC(x)) solve(dC(x)==0,x)
40000x2+20\displaystyle -\frac{40000}{x^{2}} + 20
[x == -20*sqrt(5), x == 20*sqrt(5)]

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

The domain of the cost function is (0,)(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 x0x\rightarrow0 or xx\rightarrow\infty?

+Infinity +Infinity

As the xx 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=45x=45.


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

We want x=20544.72x=20\sqrt{5}\approx 44.72 feet, and then y=1000x=100020522.36\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=V= volume, l=l= length, w=w= width, and h=h= height. We'll cut out an hh by hh square from each side (when we fold up the sides, hh will be the height of the box).

Step 2 Draw a picture.

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

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

%var h expand((5-2*h)*(4-2*h)*h)
4*h^3 - 18*h^2 + 20*h

Steps 5 and 6

V(h)=4*h^3 - 18*h^2 + 20*h dV(h)=derivative(V,h);show(dV(h)) solve(dV(h)==0,h)
12h236h+20\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>0h>0, since it is a length. We also need h<2h<2, because w=42hw=4-2h, and if h2h\ge2, then w0w\le 0.

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

0 0

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

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


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