Calculus Optimization problem 
Help with the problem??
The cost of building the pipeline is $\$3$ million per mile in the water, and $\$4$ million per mile on land. Hence, the cost of the pipeline depends on the location of point $P$. where it meets shore. What would be the most economical route of the pipeline?
 A: Physics Approach:
In this solution, all units are ignored.  Consider an imaginary wave that travels along the water's surface at the speed $v_a:=\frac{1}{3}$ and on the surface of the land at the speed $v_b:=\frac{1}{4}$ .  The total time it travels along the polygonal line $APB$ is $t( P):=\frac{AP}{v_a}+\frac{BP}{v_b}=3\cdot AP+4\cdot BP$.  By Fermat's Principle of Least Time, the wave will take the time minimizing route.  If $Q$ is the minimizing point, then by Snell's Law, we must have $\frac{\sin\left(\theta_a\right)}{\sin\left(\theta_b\right)}=\frac{v_a}{v_b}=\frac{4}{3}$, if $\theta_a$ and $\theta_b$ is the angle $AQ$ and $BQ$ make with the normal line to the water-land boundary.
Let $C$ and $D$ be the feet of the perpendiculars from $A$ and $B$ to the water-land boundary.  We have $CD=4$.  Let $x:=CQ$.  Then, $$\sin\left(\theta_a\right)=\cos(AQC)=\frac{x}{\sqrt{x^2+4}}\text{ and }\sin\left(\theta_b\right)=\cos(BQD)=\frac{4-x}{\sqrt{(4-x)^2+1}}\,.$$
From $\frac{\sin\left(\theta_a\right)}{\sin\left(\theta_b\right)}=\frac{4}{3}$, we have
$$\frac{3x}{\sqrt{x^2+4}}=\frac{4(4-x)}{\sqrt{(4-x)^2+1}}\,.$$
The rest is just as in Michael Galuza's solution, where we obtain $x\approx 3.178466628$.
A: Using the figure in the post, let us define the coordinates of the points : $A (0,2)$ , $P (0,x)$, $B (d,-1)$.
Now, for computing $d$, the square of the distance between points $A$ and $B$ is given by $$D_{AB}^2=(x_A-x_B)^2+(y_A-y_B)^2=(0-d)^2+(2+1)^2=d^2+9=5^2=25$$ which makes $d=4$. Similarly $$D_{AP}^2=(x_A-x_P)^2+(y_A-y_P)^2=(0-x)^2+(2-0)^2=x^2+4$$ $$D_{BP}^2=(x_B-x_P)^2+(y_B-y_P)^2=(4-x)^2+(-1-0)^2=1+(4-x)^2$$ So, the cost function is $$C=3 \sqrt{x^2+4}+4\sqrt{1+(4-x)^2}$$ and this is what we need to minimize.
The derivative of $C$ with respect to $x$ is given by $$C'=\frac{3 x}{\sqrt{x^2+4}}-\frac{4 (4-x)}{\sqrt{1+(4-x)^2}}$$ Uisng $C'=0$, we can then rewrite  $$\frac{\sqrt{1+(4-x)^2}}{\sqrt{x^2+4}}=\frac{4 (4-x)}{3x}$$ Squaring, reducing to same denominator and simplifying leads to $$7 x^4-56 x^3+167 x^2-512 x+1024=0$$ which is not pleasant since it is a quartic. Plotting it between $x=0$ and $x=4$ which are our bounds shows that the root is close to $x=3$. So, we can start Newton method using $x_0=3$ and the iterates will be given by $$x_{n+1}=\frac {21 x_n^4-112 x_n^3+167 x_n^2-1024}{28 x_n^3-168 x_n^2+334 x_n-512}$$ that is to say $3.17293$, $3.17846$ , $3.17847$ which is the solution for six significant figures.
A: Let $A=(0,2)$. Let's find coordinates of $B$. We have a right triangle with hypothenuse $5$ and side $2 + 1 = 3$; so, another side is $\sqrt{5^2 - 3^2} = 4$ and $B = (4,-1)$. Now,
$$
AP = \sqrt{2^2 + x^2},\enspace BP = \sqrt{(4-x)^2 + 1^2}.
$$
Total cost is
$$
C(x) = 3\cdot AP + 4\cdot PB = 3\sqrt{\strut x^2 + 4} + 4\sqrt{\strut 1 + (4-x)^2}.
$$
We need to minimize $C(x)$. Find derivative:
$$
\frac{dC}{dx} = \frac{3x}{\sqrt{x^2+4}} - \frac{4(4-x)}{\sqrt{1 + (4-x)^2}}.
$$
This equation simplified to
$$
7x^4 - 56x^3 + 167x^2 - 512x + 1024=0;
$$
(not so simpler, hm ;) it's better to solve it numerically:
$$
x \approx 3.178466628,\enspace C(x) \approx 16.44279212\\
x\approx 4.968627813,\enspace C(x)\approx 21.63697470
$$
So, optimal $x$ is $\approx 3.178466628$.
As you can see, this problem is analogous to problem in optics: light passing through a boundary between two different isotropic media, and asked to find light way. We've got Snell's law!
A: The total cost is $C=3AP+4PB$. 
Once you notice that the figure may be inscribed in a $3/4/5$ triangle, you can write $AP=\sqrt {x^{2}+4} $ and $PB=\sqrt {(4-x)^{2}+1}$. 
Therefore, $C(x)=3\sqrt {x^{2}+4}+4\sqrt {(4-x)^{2}+1}$ which has its minimum at $x=3.17$ good to two places. 
function http://www4a.wolframalpha.com/Calculate/MSP/MSP464820a1ahb704g18121000065437e5daa93367a?MSPStoreType=image/gif&s=57&w=433.&h=197.&cdf=Coordinates&cdf=Tooltips
