```python
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
```

\begin{equation}
\begin{array}{ll}
\min_{x_1,x_2} & -x_1-x_2 \\
\text{s. a. }  & 50x_1+24x_2\leq 2400 \\
               & 30x_1+33x_2\leq 2100 \\
               & -x_1\leq -45 \\
               & -x_2\leq -5,
\end{array}
\end{equation}


```python

```


```python
def x2_v1(x1):
    return (2400 - 50*x1)/24
def x2_v2(x1):
    return (2100 - 30*x1)/33
```


```python
x1 = np.linspace(43, 47)
```


```python
x1 = np.linspace(0, 100)
```


```python
plt.plot(x1, x2_v1(x1), 'magenta', label = "Eq1") #desigualdad 1
plt.plot(x1, x2_v2(x1), label = "Eq2") # desigualdad 2
#plt.plot([45, 45], [0, 25], 'k')
#plt.plot([43, 47], [5, 5], 'r')
#plt.xlim(xmin = 44, xmax = 46)
#plt.ylim(ymin = 4.5, ymax = 6.5)
#plt.scatter([45], [6.25], color = 'red')
#plt.fill_between(np.array([45, 45.6]), x2_v1(np.array([45, 45.6])),
#                5*np.ones(2), alpha = .2, color = 'orange')

plt.hlines(5, 0, 100, label = "Eq4")
plt.vlines(45, -100, 100, color = "r", label = "Eq3")
plt.legend()
plt.xlabel("$x_1$", fontsize = 18)
plt.ylabel("$x_2$", fontsize = 18)
plt.show()
```


```python
plt.plot(x1, x2_v1(x1), 'magenta', label = "Eq1") #desigualdad 1
plt.plot(x1, x2_v2(x1), label = "Eq2") # desigualdad 2
plt.hlines(5, 0, 100, label = "Eq4")
plt.vlines(45, -100, 100, color = "r", label = "Eq3")
plt.legend()
plt.xlabel("$x_1$", fontsize = 18)
plt.ylabel("$x_2$", fontsize = 18)
plt.xlim(xmin = 44, xmax = 70)
plt.ylim(ymin = 2, ymax = 48)
plt.show()
```


```python
plt.plot(x1, x2_v1(x1), 'magenta', label = "Eq1") #desigualdad 1
plt.plot(x1, x2_v2(x1), label = "Eq2") # desigualdad 2
plt.hlines(5, 0, 100, label = "Eq4")
plt.vlines(45, -100, 100, color = "r", label = "Eq3")
plt.scatter([45], [6.25], color = 'k', s = 105)
#plt.fill_between(np.array([45, 45.6]), x2_v1(np.array([45, 45.6])),
#                5*np.ones(2), alpha = .2, color = 'orange')
plt.legend()
plt.xlabel("$x_1$", fontsize = 18)
plt.ylabel("$x_2$", fontsize = 18)
plt.xlim(xmin = 44, xmax = 47)
plt.ylim(ymin = 2, ymax = 10)
plt.grid()
plt.show()
```


```python
import scipy.optimize as opt
```


```python
c = np.array([-1, -1])              ## Coeficientes de la función objetivo
A = np.array([[50, 24], [30, 33]])
b = np.array([2400, 2100])
x1_bound = (45, None)
x2_bound = (5, None)
```


```python
c
```




    array([-1, -1])




```python
A
```




    array([[50, 24],
           [30, 33]])




```python
B = np.array([[2, 1, 0],[0, 1, -2],[1, 0, 4]]); B
```




    array([[ 2,  1,  0],
           [ 0,  1, -2],
           [ 1,  0,  4]])




```python
opt.linprog?
```


```python
res = opt.linprog(c, A_ub = A, b_ub = b,
                  bounds=(x1_bound, x2_bound), options={'disp':True})
```

    Optimization terminated successfully.
             Current function value: -51.250000  
             Iterations: 4



```python
res
```




         fun: -51.25
     message: 'Optimization terminated successfully.'
         nit: 4
       slack: array([  0.  , 543.75,   0.  ,   1.25])
      status: 0
     success: True
           x: array([45.  ,  6.25])




```python
res.x
```




    array([45.  ,  6.25])



## Actividad


```python

```

4a688622cf7586046166ff913890bb239921df5c
ipynb
Jupyter Notebook
Modulo1/SolucionGraficaPL.ipynb
douglasparism/SimulacionM2018
85953efb86c7ebf2f398474608dfda18cb4cf5b8
MIT
Modulo1/SolucionGraficaPL.ipynb
douglasparism/SimulacionM2018
85953efb86c7ebf2f398474608dfda18cb4cf5b8
MIT
Modulo1/SolucionGraficaPL.ipynb
douglasparism/SimulacionM2018
85953efb86c7ebf2f398474608dfda18cb4cf5b8
MIT
Qwen/Qwen-72B
1. YES
2. YES