First, we’ll pull the \(x\) and \(y\) variables into two seperate vectors:
Now, to get the regression line, we can use the lm function, passing in our dependent variable \(y\) and our independent variable \(x\):
##
## Call:
## lm(formula = y ~ x)
##
## Coefficients:
## (Intercept) x
## -14.800 4.257
The output of the linear regression model tells us that the equation for the regression line is:
\(y=4.257x-14.800\)
These types of problems are often easier to solve with Python’s sympy, so we’ll use that below:
import sympy as sym
x,y = sym.symbols("x y")
f = 24*x - 6*x*y**2 - 8*y**3
gradient = sym.derive_by_array(f, (x,y))
hessian = sym.Matrix(sym.derive_by_array(gradient, (x, y)))
#hessian
stationary_points = sym.solve(gradient, (x,y))
for p in stationary_points:
value = f.subs({x: p[0], y: p[1]})
hess = hessian.subs({x: p[0], y: p[1]})
eigenvals = hess.eigenvals()
if all(ev > 0 for ev in eigenvals):
print("Local minimum at {} with value {}".format(p, value))
elif all(ev < 0 for ev in eigenvals):
print("Local maximum at {} with value {}".format(p, value))
elif any(ev > 0 for ev in eigenvals) and any(ev < 0 for ev in eigenvals):
print("Critical point at ({},{},{}) which are also saddle points".format(p[0],p[1], value))
## Critical point at (-4,2,-64) which are also saddle points
## Critical point at (4,-2,64) which are also saddle points
Inspiration for code: https://stackoverflow.com/questions/50081980/finding-local-maxima-and-minima-of-user-defined-functions
\(R(x,y)=x(81-21x+17y) + y(40+11x-23y)\) \(R(x,y)=81x-21{ x }^{ 2 }+17xy+40y+11xy+23{ y }^{ 2 }\)
Simplified, the revenue function is: \(R(x,y)=81x+40y+28xy-21{ x }^{ 2 }-23{ y }^{ 2 }\)
To solve this, we just need to solve where R(2.30, 4.10):
## [1] 116.62
This problem is similar to the last, except this time we’ll be looking for the derivative of the cost curve. In order to get the derivative, we’ll need to solve the cost funtion. To do that we can take advantage of a key piece of information - we know that \(x\) + \(y\) have committed to produce 96 units of product each week, so:
\(x+y=96\) which is we can use to solve for \(x\): \(x=96-y\), which we can then substitute into our cost function:
\(C(96-y,y)=\frac { 1 }{ 6 } { (96-y) }^{ 2 }+\frac { 1 }{ 6 } { y }^{ 2 }+7(96-y)+25y+700\)
After several steps of simplification we get the following cost curve:
\(C(y)=\frac { 1 }{ 3 } { y}^{ 2 }-14y+2908\)
Now, taking the derivative, we get:
\(C'(y)=\frac { 2 }{ 3 } { y }-14\)
To find the minimum of the derivative, we’ll need to set it equal to 0 and solve:
\(C'(y)=\frac { 2 }{ 3 } { y }-14=0\)
Solving for \(y\) we get \(y=21\)
Plugging this back into our original function \(x+y=96\) we get \(x\) is 75.
SO, we should produce 75 units in Los Angeles and 21 units in Denver.
\(\iint { ({ e }^{ 8x+3y })dA;R:2\le x\le 4\quad and\quad 2\le y\le 4 }\)
## (1 - exp(6))*exp(22)/24 - (1 - exp(6))*exp(38)/24
I love SYMPY.