<s>[INST] 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?
 [/INST] 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.
</s>