# CHEM 1000 - Spring 2022
Ryan Wheat, University of Pittsburgh

## Recitation

For this recitation, we'll focus on:
- Graphical Interpolation for Optimization
- Lagrange Multipliers Practice
---

The goal of Chapter 6 is to give a cursory overview of the vastly expanding field that is "optimization algorithms". All fields, in some form, deal with optimizing something with known constraints. It is to your advantage to hold onto the conceptual aspects of this content.

Please follow along with recitation and complete the following questions to gain credit for this assignment.

### Part A: Simionescu Function

Sometimes determining the analytical solution to a function is not practical. In this case, one might wish to better understand the function graphically to then interpolate the extrema. Today we will be working with another function, the Simionescu function, which is unique not for the function itself, but how the constraint is defined. Here, f(x, y) is the function and g(x, y) is the constraint.

$$
f(x, y)=0.1xy
$$

$$
g(x, y)=x^{2}+y^{2}-(1+0.2cos(8tan^{-1}(x/y)))^{2}
$$

#### Run the code in each cell and answer the three questions below to get credit for this recitation.

1. Calculate all partial derivatives.
2. Describe the constraint on the basis of symmetry.
3. Where are the maxima and minima?


```python
from sympy import init_session
init_session()
```


```python
# Calculate derivatives here with sympy. Note that arctan(x) = atan(x).

dfdx = 
dfdy = 
dgdx = 
dgdy = 
```

Use this website to plot the constraint function. Describe what you see? What symmetries do you notice? Why do you think this constraint makes optimization difficult? Think critically about how a computer might search for minima and maxima...

https://www.desmos.com/calculator


```python
# Write your description of the constraint function below.


```

We can extend our original function in three dimensions by setting it equal to z.

$$
f(x,y) = 0.1xy = z
$$

Follow along with recitation to learn how to graphically determine the maxima and minima. In the cell below, write (approximately) what values correspond to the maxima and minima.


```python
maxima =
minima = 
```

### Part B: Company Startup

Let's say that you are starting a company and need to hire staff and order materials. The materials (m) you need can be ordered in bulk at 50 dollars for each crate. You need to hire staff (s) to convert the materials into some product (think assembly line) at 20 dollars per hour. After consulting an entrepeneur and an engineer, you find that similar companies have used this model:

$$
f(m,s) = 5m^{2}s+2s^{2}m
$$

#### Run the code in each cell and answer the three questions below to get credit for this recitation.

1. Your company has a startup fund of 600 dollars. Optimize your initial spending given the model above.
2. Your friend is also starting a company and has been instructed to use the same model. However, you decided to give your friend two crates of material and to transfer one of your workers to their company to start production. Modify the model with these initial conditions.
3. Your friend has applied for a startup fund and was awarded 480 dollars. Optimize spending to maximize their efficiency.


```python
# Calculate your optimal spending.

f = 5*s*m**2 + 2*m*s**2
g = 
h = 
```


```python
# Write your new model here...

f_new = 
```


```python
# Calculate the optimal spending for your friend.

f_new = 
g = 
h = 
```

3ada9e9a68f043f69586d828b68d95b250736a59
ipynb
Jupyter Notebook
recitation/06-optimizations.ipynb
ghutchis/chem1000
07a7eac20cc04ee9a1bdb98339fbd5653a02a38d
CC-BY-4.0
2020-06-23T18:44:37.000Z
2022-03-14T10:13:05.000Z
recitation/06-optimizations.ipynb
ghutchis/chem1000
07a7eac20cc04ee9a1bdb98339fbd5653a02a38d
CC-BY-4.0
recitation/06-optimizations.ipynb
ghutchis/chem1000
07a7eac20cc04ee9a1bdb98339fbd5653a02a38d
CC-BY-4.0
2021-07-29T10:45:23.000Z
2021-10-16T09:51:00.000Z
Qwen/Qwen-72B
1. YES
2. YES