Author | Kenneth Massey |

Date | 2017-03-03T13:12:34 |

Project | ce29b7fe-0e89-4b55-8737-8719378e0588 |

Location | city-problems.sagews |

Original file | city-problems.sagews |

`%md`

`# Problem 1`

`## Part (a)`

`The diagram of the city and two hospitals is included below. Areas shaded green are closer to hospital 2,`

`and areas shaded purple are closer to hospital 1.`

`The line separating the regions is perpendicular to the line between H1 and H2, and goes through the midpoint (6,3).`

`The slope between H1 and H2 is $\frac{9-3}{5-1} = 3/2$, so the slope of the dividing line is -2/3,`

`and therefore the equation is $y=3-2/3(x-6)$, or $x=\frac{-2}{3}y+8$.`

`![](hospitals.png)`

The diagram of the city and two hospitals is included below. Areas shaded green are closer to hospital 2, and areas shaded purple are closer to hospital 1.

The line separating the regions is perpendicular to the line between H1 and H2, and goes through the midpoint (6,3).

The slope between H1 and H2 is $\frac{9-3}{5-1} = 3/2$, so the slope of the dividing line is -2/3,
and therefore the equation is $y=3-2/3(x-6)$, or $x=\frac{-2}{3}y+8$.

`%md`

`## Part (b)`

`To get the average distance, we integrate the distance to the hospital over each region. Then divide that result by the area of the city.`

`$$D_{avg} = \frac{ \int_0^6 \int_0^{-2/3y+8} \sqrt{(x-3)^2+(y-1)^2} dx dy + \int_0^6\int_{-2/3y+8}^{10} \sqrt{(x-9)^2+(y-5)^2} dx dy}{60}$$`

`Doing the integrals in WolframAlpha:`

`![](1b-1.png)`

`![](1b-2.png)`

`So the average distance is $\frac{100.611 + 62.68}{60} = 2.72$ miles.`

To get the average distance, we integrate the distance to the hospital over each region. Then divide that result by the area of the city.

$$D_{avg} = \frac{ \int_0^6 \int_0^{-2/3y+8} \sqrt{(x-3)^2+(y-1)^2} dx dy + \int_0^6\int_{-2/3y+8}^{10} \sqrt{(x-9)^2+(y-5)^2} dx dy}{60}$$

Doing the integrals in WolframAlpha:

So the average distance is $\frac{100.611 + 62.68}{60} = 2.72$ miles.

`# This demonstrates how to do the integrals in Sage.`

`# The 'assume' statements are required following warning prompts from the symbolic integrator.`

`var('x y')`

`assume(y<12)`

`assume(y+3>0)`

`assume(y!=1)`

`assume(y!=5)`

`I1=integrate( integrate( sqrt((x-3)^2+(y-1)^2) ,x,0,-2/3*y+8), y,0,6).N()`

`I2=integrate( integrate( sqrt((x-9)^2+(y-5)^2) ,x,-2/3*y+8,10), y,0,6).N()`

`I1`

`I2`

`(I1+I2)/60`

($\displaystyle x$, $\displaystyle y$)

$\displaystyle 100.610768962$

$\displaystyle 62.6778777973$

$\displaystyle 2.72147744599$

`# This demonstrates how to do the integrals numerically in Sage.`

`var('x y')`

`I1=numerical_integral( lambda y: numerical_integral(lambda x: sqrt((x-3)^2+(y-1)^2) ,0,-2/3*y+8)[0], 0,6)[0]`

`I2=numerical_integral( lambda y: numerical_integral(lambda x: sqrt((x-9)^2+(y-5)^2) ,-2/3*y+8,10)[0], 0,6)[0]`

`I1`

`I2`

`(I1+I2)/60`

($\displaystyle x$, $\displaystyle y$)

$\displaystyle 100.610768962$

$\displaystyle 62.6778777973$

$\displaystyle 2.72147744599$

`%md`

`$$\frac{d}{dx} \frac{\partial }{\partial x}$$`

$$\frac{d}{dx} \frac{\partial }{\partial x}$$