CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
calculuslab

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: calculuslab/Calculus_Lab
Path: blob/main/141-Labs/Lab 08 - Optimization.ipynb
Views: 491
Kernel: SageMath

Lab 08 - Optimization

Overview

The methods learned in Chapter 4 of the text for finding extreme values have practical applications in many areas of life. In this lab, we will use SageMath to help with solving several optimization problems.

Important SageMath Commands Introduced in this Lab

ParseError: KaTeX parse error: Undefined control sequence: \hfill at position 32: …|l|l|} \hline \̲h̲f̲i̲l̲l̲ ̲\textbf{Command…
4.6

General Steps for Solving Optimization Problems

The following strategy for solving optimization problems is outlined on Page 264 of the text.

  1. Read and understand the problem. What is the unknown? What are the given quantities and conditions?

  2. Draw a picture. In most problems it is useful to draw a picture and identify the given and required quantities in the picture.

  3. Introduce variables. Asign a symbol for the quantity, let us call it QQ, that is to be maximized or minimized. Also, select symbols for other unknown quantities. Use suggestive notation whenever possible: AA for area, hh for height, rr for radius, etc.

  4. Write an equation. Express QQ in terms of some of the other unknown variables. If QQ has been expressed as a function of more than one variable, use the given information to find relationships (in the form of equations) among these variables. Then use the equations to eliminate all but one of the variables in the expression for QQ.

  5. Test the critical points and endpoints in the domain of the variable. Use the methods of Section 4.1 to find the absolute\textit{absolute} maximum or minimum value.

Example 1

A farmer has 2400 ft of fencing and wants to fence off a rectangular field that borders a straight river. He does not need to fence along the river. What are the dimensions of the field that has the largest area?

Optimization problems often use the same variables, so you should start every new problem with reset()\textbf{reset}() to clear out variables defined during previous examples.

reset()

We will now assign our given information about the perimeter. We will use ll to represent the length of the fence and ww to represent the width of the fence. Note: we can create multiple variables at the same time by separating the assignment with commas.

Since we do not need to fence the side bordering the river, our equation for the perimeter is 2l+w2l + w.

l, w = var('l', 'w') perimeter = 2*l + w == 2400

We are trying to maximize the area of the field, which is given by l×wl \times w.

def A(l,w): return l*w

We can now use the perimeter equation to solve either of the variables in terms of the other and substitute this value into our area function to get area as a function of one variable.

solve(perimeter, l)

We now set l=12w+1200l = -\frac{1}{2}w + 1200 and redefine AA as function which only depends on ww.

l = -1/2 * w + 1200 A(l,w)
def A(w): return -1/2 *(w-2400)*w A(w)

Now, we find the critical points of A(w).A(w).

solve(diff(A(w),w) == 0, w)

We need to check the area of the field at the critical point w=1200w = 1200 and at the endpoints. Since both ll and ww represent lengths, they both must be nonnegative. Therefore, one endpoint is w=0w = 0. To find the other, we solve the inequality l>0l > 0 for ww.

solve(l > 0, w)

Hence, our other endpoint is w=2400.w = 2400. We now find the area of the field at each of these values for ww. We can use the print()\textbf{print}(\dots) command to output each line of code and not just the last.

print(A(0)) print(A(1200)) print(A(2400))

Therefore, the area of the field is maximized when w=1200w = 1200. To find the corresponding value of ll, we can substitute w=1200w = 1200 into the expression for ll.

l(w = 1200)

Hence, the dimensions which maximize the area of the field are a length of 600 ft and a width of 1200 ft.

Example 2

Find the point on the line x3+y5=1\frac{x}{3} + \frac{y}{5} = 1 that is closest to the origin.

Example 3

A rectangular storage container with an open top is to have a volume of 10 m3^3. The length of its base is twice the width. Material for the base costs $$10persquaremeter.Materialforthesidescosts10 per square meter. Material for the sides costs $$6 per square meter. Find the cost of materials for the cheapest such container.

Example 4

A man launches his boat from a point AA on the bank of a straight river, 3 km wide, and wants to reach point BB, 8 km downstream on the opposite bank, as quickly as possible. He could row his boat directly across the river to point CC and then run to BB, or he could row directly to BB, or he could row to some point DD between CC and BB and then run to BB. If he can row 6 km/hr and run 8 km/hr, where should he land to reach BB as soon as possible?