Calculus I Optimization Problem - Maximization of Profit Calculus problem that I've been trying to get my head around. 
Problem: A company can sell 20 products if it charges $40 per product.
For each dollar decrease or increase in the price, the company can sell one more or one less product, respectively. The total cost of producing q products is C(q) = 32q + 100. What is the maximum profit that the company can achieve from manufacturing and selling this product?
I tried to find the profit function by subtracting cost from revenue, then took the derivative of said function, but got lost along the process. I know the answer is supposed to be $96. 
 A: Let $p$ be the price in dollars and $n(p)$ be the number of items sold at price $p$.  We know $n(40) = 20$ and 
$$  n(p) = 20 - (p-40) = 60 - p \text{.}  $$
(This says that for every dollar we raise the price over $40$, the number of units sold decreases by $1$ and for every dollar we lower the price under $40$, the number of units sold increases by $1$.)
Let $r(p)$ be the revenue at a given price.  We have \begin{align*}
r(p) &= n(p) \cdot p  \\
    &= (60 - p) \cdot p  \\
    &= 60p - p^2  \text{.}
\end{align*}
We know the cost is $c(n) = 32n+100$.  Inserting $n(p)$ we find that the cost of producing the $n(p)$ items sellable at price $p$, we have 
\begin{align*}
c(p) &= 32(60-p) + 100  \\
    &= 1920 - 32p  \text{.}
\end{align*}
Let $P(p)$ be the profit at price $p$ if we produce exactly as many items as will be sold at that price.  \begin{align*}
P(p) &= r(p) - c(p)  \\
    &= (60p-p^2) - (1920 - 32p)  \\
    &= -1920 + 92p - p^2  \text{.}
\end{align*}
Then 
$$  P'(p) = 92 - 2p  $$
and this is zero when $p = 46$ at which price, $P(46) = 196$.  Checking that this is a maximum, 


*

*using the second derivative:  $P''(46) = -2$, so we have a local maximum, or 

*using the first derivative:  $P'(45) = 2$ and $P'(47) = -2$, so we have a local maximum.


Either way, we should compare with the natural endpoints to make sure there isn't a better optimum at a place where the derivative is not zero.  (For instance the maximum and minimum of a non-horizontal line are achieved a the endpoints of the feasible interval.)  In this case, we cannot make fewer than $0$ items, corresponding to a price of $60$.  $P(60) = 0$, unsurprisingly.  Also, we cannot (sanely) price below zero and $P(0) = -1920$, which is far below the maximum found above.
The maximal profit is obtained when the price is \$46, at which price the profit is \$196.
A: First thing to notice is that you cannot decrease the number of products by more than $n=19$ and you cannot increase it by more that $n=39$. The profit function would be:
$$P(n)=(20+n)(40-n)$$
Logically, to maximise the net profit is to maximise $NP(n)=P(n)-C(n)$.
$$\begin{align*}NP(n)&=P(n)-C(n)\\&=(20+n)(40-n)-32(20+n)-100\\&=-n^2-12n+60\end{align*}$$
This is the equation of a concave down parabola, so it has a maximum.
$$\begin{align*}
\frac{\mathrm dNP(n)}{\mathrm{d}n}=0&\Leftrightarrow -2n-12=0\\&\Leftrightarrow n=-6\text{ verifies } -19\leq n \leq 39
\end{align*}$$
You need to decrease the number of products by $6$ and the net profit would be $NP(6)=96\,\$$.
A: 
A company can sell 20 products if it charges $40 per product. For each dollar decrease or increase in the price, the company can sell one more or one less product, respectively

That gives the quantity $q$ for the price $p$
$$q = 20 + 40 - p$$
$$q = 60 - p$$

The total cost of producing q products is $C(q) = 32q + 100$

Thus, the profit $P$ is the quantity $q$ by the price $p$ minus production cost
$$P = qp - (32q + 100)$$
And, by plugging the value of $q$ above
$$ P = p(60 - p) - 32(60 - p) $$
$$ P = -p^2 + 92p - 2020 $$
The leading coefficient is negative, meaning the quadratic function is a downward parabola. Thus, finding the price of the curve at the top will give you the maximum profit. That is, for which $p$ is the derivative zero?
$$ P' = -2p + 92 $$
$$ -2p + 92 = 0 $$
$$ p = 46 $$
We know that for a price of $46, we get the maximum profit. Plugging that price into the profit equation gives the maximum profit
$$ P = -p^2 + 92p - 2020 $$
$$ maxP = -46^2 + 92\cdot46 - 2020 $$
$$ maxP = 96 $$
 (image from Wolfram Alpha)
