\section{Related Rates}\label{sec:RelatedRates}
When defining the derivative $f^{\prime}\left( x\right)$,
we define it to be exactly the rate of change of $%
f\left( x\right) $ with respect to $x$. Consequently, any question about
rates of change can be rephrased as a question about derivatives.
\textbf{When we calculate derivatives, we are calculating rates of change}. Results
and answers we obtain for derivatives translate directly into results and
answers about rates of change. Let us look at
some examples where more than one variable is involved, and where our job is to
analyze and exploit relations between the rates of change of these
variables. The mathematical step of relating the rates of change turns out
to be largely an exercise in differentiation using the chain rule or
implicit differentiation. This explains why some textbooks place this
section shortly after the sections on the chain rule and implicit
differentiation.

Suppose we have two variables $x$ and $y$ (in most problems the
letters will be different, but for now let's use $x$ and $y$) which
are both changing with time.  A ``related rates'' problem is a problem
in which we know one of the rates of change at a given instant---say,
$\ds \dot x = dx/dt$---and we want to find the other rate $\ds \dot y = dy/dt$ at that
instant. (The use of $\ds \dot x$ to mean $dx/dt$ goes back to Newton and
is still used for this purpose, especially by physicists.)

If $y$ is written in terms of $x$, i.e., $y=f(x)$, then this is easy
to do using the chain rule:
$$\dot y = \frac{dy}{dt}=\frac{dy}{dx}\cdot\frac{dx}{dt}=\frac{dy}{dx}\dot x.$$
That is, find the derivative of $f(x)$, plug in the value of
$x$ at the instant in question, and multiply by the given value of
$\ds \dot{x}=dx/dt$ to get $\ds \dot{y}=dy/dt$.

\begin{example}{Speed at which a Coordinate is Changing}{SpeedCoordinate}
Suppose an object is moving along a path described by $\ds y=x^2$, that
is, it is moving on a parabolic path. At a particular time, say $t=5$,
the $x$ coordinate is 6 and we measure the speed at which the $x$ coordinate of the object is
changing and find that $dx/dt = 3$.

At the same time, how fast is the $y$ coordinate changing?
\end{example}

\begin{solution}
Using the chain rule, $\ds dy/dt = 2x\cdot dx/dt$. At $t=5$ we know that
$x=6$ and $dx/dt=3$, so $dy/dt = 2\cdot 6\cdot 3 = 36$.
\end{solution}

In many cases, particularly interesting ones,
$x$ and $y$ will be related in some other way, for example
$x=f(y)$, or $F(x,y)=k$, or perhaps $F(x,y)=G(x,y)$, where $F(x,y)$
and $G(x,y)$ are expressions involving both variables.  In all cases, you
can solve the related rates problem by taking the derivative of both sides,
plugging in all the known values (namely, $x$, $y$, and $\ds \dot{x}$), and
then solving for $\ds \dot{y}$.

To summarize, here are the steps in doing a related rates problem.

\begin{formulabox}[Steps for Solving Related Rates Problems]
\begin{enumerate}
	\item	Decide what the two variables are.
	\item	Find an equation relating them.
	\item	Take $d/dt$ of both sides.
	\item	Plug in all known values at the instant in question.
	\item	Solve for the unknown rate.
\end{enumerate}
\end{formulabox}

\begin{example}{Receding Airplanes}{RecedingAirplane}
A plane is flying directly away from you at 500 mph at an altitude of
3 miles.  How fast is the plane's distance from you increasing at the
moment when the plane is flying over a point on the ground 4 miles
from you?
\end{example}

\begin{solution}
To see what's going on, we first draw a schematic representation of
the situation, as in Figure~\ref{fig:airplane}.

Because the plane is in level flight directly away from you, the rate
at which $x$ changes is the speed of the plane, $dx/dt=500$. The
distance between you and the plane is $y$; it is $dy/dt$ that we wish
to know. By the Pythagorean Theorem we know that $\ds x^2+9=y^2$. Taking
the derivative:
$$ 2x \dot x = 2y\dot y.$$
We are interested in the time at which $x=4$; at this time we know
that $\ds 4^2+9=y^2$, so $y=5$. Putting together all the information we
get
$$2(4)(500)=2(5)\dot y.$$
Thus, $\ds \dot y=400$ mph.
\end{solution}

\figure[H]
\centerline{\vbox{\beginpicture
\normalgraphs
%\ninepoint
\setcoordinatesystem units <.75truecm,.75truecm>
\setplotarea x from 0 to 6, y from 0 to 3
\axis bottom shiftedto y=0 /
\setlinear
\setdashes
\plot 0 0 5 3 /
\putrule from 5 0 to 5 3
\put {$\longrightarrow$} [l] at 5 3
\put {$x$} [t] <0pt,-4pt> at 2.5 0
\put {$y$} [br] <-2pt,2pt> at 2.5 1.5
\put {$3$} [l] <4pt,0pt> at 5 1.5
\endpicture}}
\caption{Receding airplane. \label{fig:airplane}}
\endfigure

\begin{example}{Spherical Balloon}{SphericalBalloon}
You are inflating a spherical balloon at the rate of 7 cm${}^3$/sec.  How
fast is its radius increasing when the radius is 4 cm?
\end{example}

\begin{solution}
Here the variables are the radius $r$ and the volume $V$.  We know $dV/dt$,
and we want $dr/dt$.  The two variables are related by the
equation $\ds V=4\pi r^3/3$.  Taking the derivative of both sides gives
$\ds dV/dt=4\pi r^2\dot r$.  We now substitute the values we know at the
instant in question: $\ds 7=4\pi 4^2\dot r$, so
$\ds \dot r=7/(64\pi)$ cm/sec.
\end{solution}

\begin{example}{Conical Container}{ConicalContainer}
Water is poured into a conical container at the rate of 10
cm${}^3$/sec.  The cone points directly down, and it has a height of
30 cm and a base radius of 10 cm; see Figure~\ref{fig:cone tank}.
How fast is the water level rising when the water is 4 cm deep (at its
deepest point)?
\end{example}

\begin{solution}
The water forms a conical shape within the big cone; its
height and base radius and volume are all increasing
as water is poured into the container.  This means that we actually have
three things varying with time: the water level $h$ (the height of the cone
of water), the radius $r$ of the circular top surface of water (the base
radius of the cone of water), and the volume of water $V$.
The volume of a cone is given by
$\ds V=\pi r^2h/3$.  We know $dV/dt$, and we want $dh/dt$.  At
first something seems to be wrong: we have a third variable, $r$, whose rate
we don't know.

However, the dimensions of the cone of water must have the same
proportions as those of the container.
That is, because of similar triangles,
$r/h=10/30$ so $r=h/3$.  Now we can eliminate $r$ from the
problem entirely: $\ds V=\pi(h/3)^2h/3=\pi h^3/27$.  We take
the derivative of both sides and plug in $h=4$ and $dV/dt=10$, obtaining
$\ds 10=(3\pi\cdot 4^2/27)(dh/dt)$.  Thus, $dh/dt=90/(16\pi)$
cm/sec.
\end{solution}

\figure[H]
\centerline{\vbox{\beginpicture
\normalgraphs
%\sevenpoint
\setcoordinatesystem units <1truecm,1truecm>
\setplotarea x from -1.5 to 1.5, y from -5 to 1
\ellipticalarc  axes ratio 3:1  360 degrees from 1.5 0 center at 0 0
\ellipticalarc  axes ratio 3:1  360 degrees from 0.75 -2.5 center at 0 -2.5
\betweenarrows {10} from 0 0.75 to 1.5 0.75
\betweenarrows {30} from 1.7 -5 to 1.7 0
\betweenarrows {$h$} from -1 -5 to -1 -2.5
\put {$r$} at 0.385 -2.1
\setlinear
\plot 1.5 0 0 -5 -1.5 0 /
%\setplotsymbol ({\teeny.})
\plotsymbolspacing=.2pt
\arrow <2pt> [0.7, 2] from 0.25 -2.1 to 0 -2.1
\arrow <2pt> [0.7, 2] from 0.50 -2.1 to 0.75 -2.1
\endpicture}}
\caption{Conical water tank. \label{fig:cone tank}}
\endfigure

\begin{example}{Swing Set}{SwingSet}
A swing consists of a board at the end of a 10 ft long rope.  Think of the
board as a point $P$ at the end of the rope, and let $Q$ be the point of
attachment at the other end.  Suppose that the swing is directly below $Q$
at time $t=0$, and is being pushed by someone who walks at 6
ft/sec from left to right.

Find (a) how fast the swing is rising after 1
sec; (b) the angular speed of the rope in deg/sec after 1 sec.
\end{example}

\begin{solution}
We  start out by asking: What is the geometric
quantity whose rate of change we know, and what is the geometric quantity
whose rate of change we're being asked about?  Note that the person pushing
the swing is moving horizontally at a rate we know.  In other words,
the  horizontal coordinate of $P$ is increasing at 6 ft/sec.  In the
$xy$-plane let us make the convenient choice of putting the origin at the
location of $P$ at time $t=0$, i.e., a distance 10 directly below the point
of attachment.  Then the rate we know is $dx/dt$, and in part
(a) the rate we want is $dy/dt$ (the rate at which $P$ is rising).  In part
(b) the rate we want is $\ds \dot{\theta}=d\theta/dt$, where $\theta$ stands for
the angle in radians through which the swing has swung from the vertical.
(Actually, since we want our answer in deg/sec, at the end we must convert
$d\theta/dt$ from rad/sec by multiplying by $180/\pi$.)

\noindent
(a)~From the diagram we see that we have a right triangle whose legs
are $x$ and $10-y$, and whose hypotenuse is 10.  Hence
$\ds x^2+(10-y)^2=100$.  Taking the derivative of both sides we obtain:
$2x\dot{x}+2(10-y)(0-\dot{y})=0$.  We now look at what we know after 1
second, namely $x=6$ (because $x$ started at 0 and has been increasing at
the rate of 6 ft/sec for 1 sec), thus $y=2$ (because we get $10-y=8$ from
the Pythagorean theorem applied to the triangle with hypotenuse 10 and
leg 6), and $\ds \dot{x}=6$.  Putting in these values gives us
$2\cdot 6\cdot 6-2\cdot 8\dot{y}=0$, from which we can easily solve
for $\ds \dot{y}$: $\ds \dot{y}=4.5$ ft/sec.

\noindent
(b)~Here our two variables are $x$ and $\theta$, so we want to use the
same right triangle as in part (a), but this time relate $\theta$ to
$x$.  Since the hypotenuse is constant (equal to 10), the best way to
do this is to use the sine: $\sin\theta=x/10$.  Taking derivatives we
obtain $\ds (\cos\theta)\dot{\theta}=0.1\dot{x}$.  At the instant in
question ($t=1$ sec), when we have a right triangle with sides
6--8--10, $\ds \cos\theta=8/10$ and $\ds \dot{x}=6$. Thus
$(8/10)\dot{\theta}=6/10$, i.e., $\ds \dot{\theta}=6/8=3/4$ rad/sec, or
approximately $43$ deg/sec.
\end{solution}

\figure[H]
\centerline{\vbox{\beginpicture
\normalgraphs
%\sevenpoint
\setcoordinatesystem units <0.5truecm,0.5truecm>
\setplotarea x from -6 to 6, y from 0 to 10
\circulararc  73.74 degrees from -6 2 center at 0 10
\circulararc  36.87 degrees from 0 8 center at 0 10
%\betweenarrows {10} from 0 0.75 to 1.5 0.75
%\betweenarrows {30} from 1.7 0 to 1.7 -5
%\betweenarrows {$h$} from -1 -2.5 to -1 -5
%\put {$r$} at 0.385 -2.1
\setlinear
\plot 0 10 6 2 /
\setdashes
\putrule from 0 0 to 0 10
\putrule from 0 2 to 6 2
\multiput {$\bullet$} at 0 10 6 2 /
\put {$P$} [l] <4pt,0pt> at 6 2
\put {$Q$} [b] <0pt,4pt> at 0 10
\put {$x$} [b] <0pt,4pt> at 3 2
\put {$y$} [r] <-4pt,0pt> at 0 1
\put {$\theta$} [tl] at 0.6 7.7
\endpicture}}
\caption{Swing. \label{fig:swing}}
\endfigure

We have seen that sometimes there are apparently more than two
variables that change with time, but in reality there are just two, as
the others can be expressed in terms of just two. However sometimes there
really are several variables that change with time; as long as you
know the rates of change of all but one of them you can find the rate
of change of the remaining one.  As in the case when there are just two
variables, take the derivative of both sides of the equation relating all of
the variables, and then substitute all of the known values and solve for
the unknown rate.

\begin{example}{Distance Changing Rate}{DistanceChangingRate}
A road running north to south crosses a road going east to west at the
point $P$.  Car A is driving north along the first road, and car B is
driving east along the second road.  At a particular time car A is $10$
kilometers to the north of $P$ and traveling at 80 km/hr, while car B
is 15 kilometers to the east of $P$ and traveling at 100 km/hr.
How fast is the distance between the two cars
changing?
\end{example}

\begin{solution}
Let $a(t)$ be the distance of car A north of $P$ at time $t$, and
$b(t)$ the distance of car B east of $P$ at time $t$, and let $c(t)$
be the distance from car A to car B at time $t$.  By the Pythagorean
Theorem, $\ds c(t)^2=a(t)^2+b(t)^2$. Taking derivatives
we get $\ds 2c(t)c'(t)=2a(t)a'(t)+2b(t)b'(t)$, so
$$\dot{c}=\frac{a\dot{a}+b\dot{b}}{c}=\frac{a\dot{a}+b\dot{b}}{\sqrt{a^2+b^2}}.$$
Substituting known values we get:
$$\dot{c}=\frac{10\cdot 80+15\cdot100}{\sqrt{10^2+15^2}}=\frac{460}{\sqrt{13}} \approx 127.6 \hbox{km/hr}$$
at the time of interest.
\end{solution}

\figure[H]
\centerline{\vbox{\beginpicture
\normalgraphs
%\sevenpoint
\setcoordinatesystem units <0.5truecm,0.5truecm>
\setplotarea x from 0 to 10, y from 0 to 6
\axis left shiftedto x=0 /
\axis bottom shiftedto y=0 /
\multiput {$\bullet$} at 0 0 0 4 7 0 /
\setdashes\setlinear
\plot 0 4 7 0 /
\put {$(0,a(t))$} [r] <-4pt,0pt> at 0 4
\put {$(b(t),0)$} [t] <0pt,-6pt> at 7 0
\put {$c(t)$} [bl] <2pt,2pt> at 3.5 2
\put {$P$} [tr] <-2pt,-2pt> at 0 0
\setsolid
\setplotsymbol ({\tenrm.})
\arrow <5pt> [.25, 1] from 0 4 to 0 5
\arrow <5pt> [.25, 1] from 7 0 to 8 0
\endpicture}}
\caption{Cars moving apart. \label{fig:departing cars}}
\endfigure

Notice how this problem differs from
Example~\ref{exa:RecedingAirplane}.  In both cases we started with the
Pythagorean Theorem and took derivatives on both sides.  However, in
Example~\ref{exa:RecedingAirplane} one of the sides was a constant
(the altitude of the plane), and so the derivative of the square of
that side of the triangle was simply zero.  In this Example, on the
other hand, all three sides of the right triangle are variables, even
though we are interested in a specific value of each side of the
triangle (namely, when the sides have lengths 10 and 15). Make sure
that you understand at the start of the problem what are the variables
and what are the constants.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Opensolutionfile{solutions}[ex]
\section*{Exercises for Section \ref{sec:RelatedRates}}

\begin{enumialphparenastyle}

\begin{ex}
Air is being pumped into a spherical balloon at a constant rate of 3 cm\textsuperscript{3}/s. How fast is the radius of the balloon increasing when the radius reaches 5cm?
\end{ex}

%%%%%%%%%%
\begin{ex}
A cylindrical tank standing upright (with one circular base on the
ground) has radius 20 cm.  How fast does the water level in the
tank drop when the water is being drained at 25 cm${}^3$/sec?
\begin{sol}
	$1/(16\pi)$ cm/s
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
A cylindrical tank standing upright (with one circular base on the
ground) has radius 1 meter.  How fast does the water level in the
tank drop when the water is being drained at 3 liters per second?
\begin{sol}
	$3/(1000\pi)$ meters/second
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
A ladder 13 meters long rests on horizontal ground and leans
against a vertical wall.  The foot of the ladder is pulled away from
the wall at the rate of 0.6 m/sec.  How fast is the top sliding down
the wall when the foot of the ladder is 5 m from the wall?
\begin{sol}
	$1/4$ m/s
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
A ladder 13 meters long rests on horizontal ground and leans
against a vertical wall. The top of the ladder is being pulled up the
wall at $0.1$ meters per second.
How fast is the foot of the ladder approaching
the wall when the foot of the ladder is 5 m from the wall?
\begin{sol}
	$-6/25$ m/s
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
A rotating beacon is located 2 miles out in the water.  Let $A$ be the
point on the shore that is closest to the beacon.  As the beacon rotates at
10 rev/min, the beam of light sweeps down the shore once each time it revolves.
Assume that the shore is straight.  How fast is the point where the beam
hits the shore moving at an instant when the beam is lighting up a point 2
miles along the shore from the point $A$?
\begin{sol}
	$80\pi$ mi/min
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
A baseball diamond is a square 90 ft on a side.  A player runs from first
base to second base at 15 ft/sec.  At what rate is the player's distance
from third base decreasing when she is half way from first to second base?
\begin{sol}
	$\ds 3\sqrt5$ ft/s
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
Sand is poured onto a surface at 15 cm${}^3$/sec, forming a
conical pile whose base diameter is always equal to its altitude.  How
fast is the altitude of the pile increasing when the pile is 3 cm
high?
\begin{sol}
	$20/(3\pi)$ cm/s
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
A boat is pulled in to a dock by a rope with one end attached to the front
of the boat and the other end passing through a ring attached to the dock
at a point 5 ft higher than the front of the boat.  The rope is being
pulled through the ring at the rate of 0.6 ft/sec.  How fast is the boat
approaching the dock when 13 ft of rope are out?
\begin{sol}
	$13/20$ ft/s
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
A balloon is at a height of 50 meters, and is rising at the constant rate
of 5 m/sec.  A bicyclist passes beneath it, traveling in a
straight line at the constant speed of 10 m/sec.  How fast is the distance
between the bicyclist and the balloon increasing 2 seconds later?
\begin{sol}
	$\ds 5\sqrt{10}/2$ m/s
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
A pyramid-shaped vat has square cross-section and stands on its
tip.  The dimensions at the top are 2 m $\times$ 2 m, and the depth is
5 m.  If water is flowing into the vat at 3 m${}^3$/min, how fast is
the water level rising when the depth of water (at the deepest point)
is 4 m?  Note: the volume of any ``conical'' shape (including
pyramids) is $(1/3)(\hbox{height})(\hbox{area of base})$.
\begin{sol}
	$75/64$ m/min
\end{sol}
\end{ex}

%%%%%%%%%%%
%\begin{ex}
%The sun is rising at the rate of $1/4$ deg/min, and appears to be
%climbing into the sky perpendicular to the
%horizon, as depicted in figure~\xrefn{fig:sunrise sunset}.
%How fast is the shadow of a 200 meter building
%shrinking at the moment when the shadow is 500 meters long?
%\begin{sol}
%	$145\pi/72$ m/s
%\end{sol}
%\end{ex}

%%%%%%%%%%
\begin{ex}
A woman 5 ft tall walks at the rate of 3.5 ft/sec away from a streetlight
that is 12 ft above the ground.  At what rate is the tip of her shadow
moving?  At what rate is her shadow lengthening?
\begin{sol}
	tip: 6 ft/s, length: $5/2$ ft/s
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
A man 1.8 meters tall walks at the rate of 1 meter per
second toward a streetlight that is 4 meters above the ground.  At
what rate is the tip of his shadow moving?  At what rate is his shadow
shortening?
\begin{sol}
	tip: $20/11$ m/s, length: $9/11$ m/s
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
A police helicopter is flying at 150 mph at a constant altitude of 0.5 mile
above a straight road.  The pilot uses radar to determine that an oncoming
car is at a distance of exactly 1 mile from the helicopter, and that this
distance is decreasing at 190 mph.  Find the speed of the car.
\begin{sol}
	$\ds 380/\sqrt3-150\approx 69.4$ mph
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
A police helicopter is flying at 200 kilometers per hour at
a constant altitude of 1 km above a straight road.  The pilot uses
radar to determine that an oncoming car is at a distance of exactly 2
kilometers from the helicopter, and that this distance is decreasing at 250
kph.  Find the speed of the car.
\begin{sol}
	$\ds 500/\sqrt3-200\approx 88.7$ km/hr
\end{sol}
\end{ex}

%%%%%%%%%%
\begin{ex}
A light shines from the top of a pole 20 m high.  An object is dropped from
the same height from a point 10 m away, so that its height at time $\ds t$
seconds is $\ds h(t)=20-9.8t^2/2$.  How fast is the object's shadow
moving on the ground one second later?
\begin{sol}
	$4000/49$ m/s
\end{sol}
\end{ex}

%\exercise The sun is setting at the rate of $1/4$ deg/min, and appears
%to be dropping perpendicular to the horizon, as depicted in
%figure~\xrefn{fig:sunrise sunset}. How fast is the shadow of a 25
%meter wall lengthening at the moment when the shadow is 50 meters long?
%\answer $25\pi/144$ m/min
%\endanswer
%
%\font\miscsymbols \endexamplemiscsymbols10 scaled 2000
%\begin{psfigure}{2.45in}{1.25in}{124.figME.ps}
%\figure
%\vbox{\beginpicture
%\normalgraphs
%\sevenpoint
%\setcoordinatesystem units <0.3truecm,0.3truecm>
%\setplotarea x from -10 to 10, y from 0 to 8
%\axis bottom shiftedto y=0 /
%\setdashes\setlinear
%\plot 5 0 -8 8 /
%\setsolid
%\setplotsymbol ({\tenrm.})
%\plot 0 0 0 3 /
%\put {\miscsymbols k} at -9 8.6
%\endpicture}\endexample
%\figrdef{fig:sunrise sunset}
%\endfigure{Sunrise or sunset.}

%\exercise
%The trough shown in figure~\xrefn{fig:trough}
%is constructed by fastening together three
%slabs of wood of dimensions 10 ft $\times$ 1 ft, and then attaching the
%construction to a wooden wall at each end.  The angle $\theta$ was
%originally $\ds 30^\circ$, but because of poor construction the sides are
%collapsing.  The trough is full of water.  At what rate (in ft${}^3$/sec)
%is
%the water spilling out over the top of
%the trough if the s\endexampleides have each fallen to an angle of $\ds 45^\circ$, and are
%collapsing at the rate of $\ds 1^\circ$ per second?
%\answer $\ds \pi\sqrt2/36$ ft$^3$/s
%\endanswer
%
%\begin{psfigure}{2.5in}{1.5in}{124.figMF.ps}
%\figure
%\vbox{\beginpicture
%\normalgraphs
%\sevenpoint
%\setcoordinatesystem units <0.9truecm,0.9truecm>
%\setplotarea x from -1 to 12, y from 0 to 4
%\setlinear\endexample
%\plot -0.5 0.866 0 0 1 0 1.5 0.866 -0.5 0.866 /
%\plot 1 0 10.4 3.42 10.9 4.29 8.9 4.29 -0.5 0.866 /
%\plot 10.9 4.29 1.5 0.866 /
%\put {$\theta$} [b] <0pt,3pt> at -0.15 0.3
%\put {$\theta$} [b] <0pt,3pt> at 1.15 0.3
%\put {$1$} [t] <0pt,-4pt> at 0.5 0
%\put {$1$} [tr] <-2pt,-2pt> at -0.25 0.433
%\put {$1$} [tl] <2pt,-2pt> at 10.65 3.853
%\put {$10$} [tl] <2pt,-2pt> at 5.7 1.71
%\circulararc 30 degrees from 0 0.3 center at 0 0
%\circulararc -30 degrees from 1 0.3 center at 1 0
%\setdashes <2pt>
%\plot 0 0 9.4 3.42 10.4 3.42 /
%\plot 9.4 3.42 8.9 4.29 /
%\plot 0 0 0 0.866 /\endexample
%\plot 1 0 1 0.866 /
%\endpicture}
%\figrdef{fig:trough}
%\endfigure{Trough.}

%\font\miscsymbols miscsymbols10 scaled 2000
%\exercise
%A light shines from the top of a pole 20 m high. A ball is falling 10
%meters from the pole, casting a shadow on a building 30 meters away,
%as shown in figure~\xrefn{fig:falling ball}.
%When the ball is 25 meters from the ground it is falling at 6 meters
%per second. How fast is its shadow moving?
%\answer 18 m/s
%\endanswer
%
%\figure
%\vbox{\beginpicture
%\normalgraphs
%\ninepoint
%\setcoordinatesystem units <.7truecm,.7truecm>
%\setplotarea x from 0 to 4.5, y fro{DistanceChangingRate}m 0 to 4
%\axis bottom /
%\setlinear
%\linethickness1pt
%\putrule from 0 0 to 0 2
%\put {$\bullet$} at 1 2.5
%\put {\miscsymbols k} at 0.05 2
%\putrule from 3 0 to 3 4
%\putrule from 3 4 to 4.5 4
%\setdashes <2pt>
%\plot 0 2 3 3.5 /
%\endpicture}
%\figrdef{fig:falling ball}
%\endfigure{Falling ball.}
%
%\exercise Do example~\xrefn{exam:departing cars} assuming that the angle
%between the two roads is 120${}^\circ$ instead of 90${}^\circ$ (that
%is, the ``north--south'' road actually goes in a somewhat northwesterly
%direction from $P$).  Recall the law of cosines:
%$\ds c^2=a^2+b^2-2ab\cos\theta$.
%\answer $\ds 136\sqrt{475}/19\approx 156$ km/hr
%\endanswer

%\exercise
%Do example~\xrefn{exam:departing cars} assuming that
%car A is 300 meters north of $P$, car B is 400 meters east of $P$, both
%cars are going at constant speed toward $P$, and the two cars will collide in
%10 seconds.
%\answer $-50$ m/s
%\endanswer
%
%\exercise
%Do example~\xrefn{exam:departing cars} assuming that
%8 seconds ago car A started from rest at $P$ and has been picking up
%speed at the steady rate of 5 m/sec${}^2$, and 6 seconds after car A
%started car B passed $P$ moving east at constant speed 60 m/sec.
%\answer $68$ m/s
%\endanswer
%
%\exercise Referring again to example~\xrefn{exam:departing cars},
%suppose that instead of car B an airplane is flying at speed $200$
%km/hr to the east of $P$ at an altitude of 2 km, as depicted in
%figure~\xrefn{fig:car and airplane}. How fast is the distance between
%car and airplane changing?
%\answer $\ds 3800/\sqrt{329}\approx 210$ km/hr
%\endanswer
%
%\figure
%\beginpicture
%\normalgraphs
%\setcoordinatesystem units <0.3truecm,0.3truecm>
%\setplotarea x from 0 to 8, y from -2 to 10
%\setlinear
%\plot 6 3 0 0 8 -2 /
%\setdashes <2pt>
%\plot 2.5 1.25 5 8.75 /
%\plot 5 -1.25 5 8.75 /
%\multiput {$\bullet$} at 2.5 1.25 5 8.75 /
%\put {$A$} [br] <-2pt,2pt> at 2.5 1.25
%\put {$B$} [b] <0pt,3pt> at 5 8.75
%\put {$c(t)$} [br] <-2pt,2pt> at 3.75 5
%\setplotsymbol ({\tenrm.})
%\setsolid
%\arrow <5pt> [.25, 1] from 2.5 1.25 to 4 2
%\arrow <5pt> [.25, 1] from 5 8.75 to 7 8.25
%\endpicture
%\figrdef{fig:car and airplane}
%\endfigure{Car and airplane.}
%
%\exercise Referring again to example~\xrefn{exam:departing cars}, suppose
%that instead of car B an airplane is flying at speed $200$
%km/hr to the east of $P$ at an altitude of 2 km, and that it is
%gaining altitude at 10 km/hr.
%How fast is
%the distance between car and airplane changing?
%\answer \hbox{$\ds 820/\sqrt{329}+150\sqrt{57}/\sqrt{47}\approx 210$ km/hr}
%\endanswer

%\exercise
%The two blades of a pair of scissors are fastened at the point $A$ as
%shown in figure~\xrefn{fig:scissors}.  Let
%$a$ denote the distance from $A$ to the tip of the blade (the point $B$).
%Let $\beta$ denote the angle at the tip of the blade that is formed by the
%line $\ds \overline{AB}$ and the bottom edge of the blade, line
%$\ds \overline{BC}$, and let $\theta$ denote the angle between
%$\ds \overline{AB}$ and the horizontal.
%Suppose that a piece of paper is cut in such a way that the center
%of the scissors at $A$ is fixed, and the paper is also fixed.  As the
%blades are closed (i.e., the angle $\theta$ in the diagram is decreased),
%the distance $x$ between $A$ and $C$ increases, cutting the paper.
%
%\itemitem{\bf a.} Express $x$ in terms of $a$, $\theta$, and $\beta$.
%
%\itemitem{\bf b.} Express $dx/dt$ in terms of $a$,
%$\theta$, $\beta$, and $d\theta/dt$.
%
%\itemitem{\bf c.} Suppose that the distance $a$ is 20 cm, and the
%angle $\beta$ is $\ds 5^\circ$.  Further suppose that $\theta$ is
%decreasing at 50
%deg/sec.  At the instant when $\ds \theta=30^\circ$, find the rate (in
%cm/sec) at which the paper is being cut.
%\answer (a) $x=a\cos\theta-a\sin\theta\cot(\theta+\beta)=
%\hbox{$a\sin\beta/\sin(\theta+\beta$), (c) $\ds \dot x\approx 3.79$ cm/s}$
%\endanswer
%
%\figure
%\vbox{\beginpicture
%\normalgraphs
%\setcoordinatesystem units <0.7truecm,0.7truecm>
%\setplotarea x from -3 to 6, y from -3.5 to 3.5
%\setlinear
%\plot 0.3 0 6 3.5 2 0 0.3 0 /
%\setdashes <2pt>
%\put {\beginpicture
%\setplotarea x from -1 to 1, y from -0.33 to 0.33
%\startrotation by 0.866 -0.5 about 0 0
%\ellipticalarc  axes ratio 3:1  360 degrees from 1 0 center at 0 0
%\stoprotation\endpicture} at -1 1
%\put {\beginpicture
%\setplotarea x from -1 to 1, y from -0.33 to 0.33
%\startrotation by 0.866 0.5 about 0 0
%\ellipticalarc  axes ratio 3:1  360 degrees from 1 0 center at 0 0
%\stoprotation\endpicture} at -1 -1
%\put {\beginpicture
%\setplotarea x from -1 to 1, y from -0.33 to 0.33
%\startrotation by 0.866 0.5 about 0 0
%\ellipticalarc  axes ratio 3:1  245 degrees from 1 0.58 center at 0 0
%\stoprotation\endpicture} at -1 -1
%\put {\beginpicture
%\setplotarea x from -1 to 1, y from -0.33 to 0.33
%\startrotation by 0.866 -0.5 about 0 0
%\ellipticalarc  axes ratio 3:1  -245 degrees from 1 -0.58 center at 0 0
%\stoprotation\endpicture} at -1 1
%\multiput {$+$} at 0 0 0.27 0.9 -1 -1 /
%\setquadratic
%\plot 0.27 0.9 3 2.5 6 3.5 /
%\plot 0.27 -0.9 3 -2.5 6 -3.5 /
%\setlinear
%\plot 0.3 0 6 -3.5 2 0 /
%\plot 6 -3.5 6 3.5 /
%\plot 2 0 6 0 /
%\put {$B$} [l] <4pt,0pt> at 6 3.5
%\put {$A$} [r] <-3pt,0pt> at 0.3 0
%\put {$C$} [br] <0pt,3pt> at 2 0
%\put {$\theta$} at 1 0.2
%\endpicture}
%\figrdef{fig:scissors}
%\endfigure{Scissors.}

\end{enumialphparenastyle}


    \filetitle{wmean}{Weighted average of time series observations}{tseries/wmean}

	\paragraph{Syntax}\label{syntax}

\begin{verbatim}
Y = wmean(X,RANGE,BETA)
\end{verbatim}

\paragraph{Input arguments}\label{input-arguments}

\begin{itemize}
\item
  \texttt{X} {[} tseries {]} - Input tseries object whose data will be
  averaged column by column.
\item
  \texttt{RANGE} {[} numeric {]} - Date range on which the weighted
  average will be computed.
\item
  \texttt{BETA} {[} numeric {]} - Discount factor; the last observation
  gets a weight of of 1, the N-minus-1st observation gets a weight of
  \texttt{BETA}, the N-minus-2nd gets a weight of \texttt{BETA\^{}2},
  and so on.
\end{itemize}

\paragraph{Output arguments}\label{output-arguments}

\begin{itemize}
\itemsep1pt\parskip0pt\parsep0pt
\item
  \texttt{Y} {[} numeric {]} - Array with weighted average of individual
  columns; the sizes of \texttt{Y} are identical to those of the input
  tseries object in 2nd and higher dimensions.
\end{itemize}

\paragraph{Description}\label{description}

\paragraph{Example}\label{example}


\chapter{Interior funcoids}

Having a funcoid $f$ let define \emph{interior funcoid} $f^{\circ}$.

\begin{defn}
  Let $f \in \mathsf{\mathsf{FCD}} (A , B) = \mathsf{\mathsf{pFCD}} \left(
  \mathscr{T} A , \mathscr{T} B \right)$ be a co-complete funcoid. Then
  $f^{\circ} \in \mathsf{\mathsf{pFCD}} \left( \dual \mathscr{T} A ,
  \dual \mathscr{T} B \right)$ is defined by the formula $\langle
  f^{\circ} \rangle^{\ast} X = \overline{\supfun{f}
  \overline{X}}$.
\end{defn}

\begin{prop}
  Pointfree funcoid $f^{\circ}$ exists and is unique.
\end{prop}

\begin{proof}
  $X \mapsto \overline{\supfun{f} \overline{X}}$ is a component
  of pointfree funcoid $\dual \mathscr{T} A \rightarrow \dual
  \mathscr{T} B$ iff $\supfun{f}$ is a component of the
  corresponding pointfree funcoid $\mathscr{T} A \rightarrow \mathscr{T} B$
  that is essentially component of the corresponding funcoid
  $\mathsf{\mathsf{FCD}} (A , B)$ what holds for a unique funcoid.
\end{proof}

It can be also defined for arbitrary funcoids by the formula $f^{\circ} =
(\CoCompl f)^{\circ}$.

\begin{obvious}
$f^{\circ}$ is co-complete.
\end{obvious}

\begin{thm}
  The following values are pairwise equal for a co-complete funcoid $f$ and $X
  \in \mathscr{T} \Src f$:
  \begin{enumerate}
    \item\label{int-simpl} $\rsupfun{f^{\circ}} X$;

    \item\label{int-set} $\setcond{ y \in \Dst f }{ \rsupfun{ f^{-
    1} } \{ y \} \sqsubseteq X }$

    \item\label{int-sset-set} $\bigsqcup \setcond{ Y \in \mathscr{T} \Dst f }{
    \rsupfun{f^{- 1}} Y \sqsubseteq X }$

    \item\label{int-sset-flt} $\bigsqcup \setcond{ \mathcal{Y} \in \mathscr{F} \Dst f
    }{ \supfun{f^{- 1}} \mathcal{Y}
    \sqsubseteq X }$
  \end{enumerate}
\end{thm}

\begin{proof}
  ~
  \begin{description}
    \item[\ref{int-simpl}=\ref{int-set}] $\setcond{ y \in \Dst f }{
    \rsupfun{f^{- 1}} \{ y \} \sqsubseteq X } = \setcond{ x \in
    \Dst f }{ \rsupfun{f^{- 1}} \{
    x \} \asymp \overline{X} } = \setcond{ x \in \Dst f
    }{ \{ x \} \asymp \supfun{f}
    \overline{X} } = \overline{\supfun{f} \overline{X}} =
    \rsupfun{f^{\circ}} X$.

    \item[\ref{int-set}=\ref{int-sset-set}] If $\rsupfun{f^{- 1}} Y \sqsubseteq X$ then (by
    completeness of $f^{- 1}$) $Y = \setcond{ y \in Y }{
    \rsupfun{f^{- 1}} \{ y \} \sqsubseteq X }$ and thus
    \[ \bigsqcup \setcond{ Y \in \mathscr{T} \Dst f }
       { \rsupfun{f^{- 1}} Y \sqsubseteq X }
       \sqsubseteq \setcond{ y \in \Dst f }{
       \rsupfun{f^{- 1}} \{ y \} \sqsubseteq X } . \]
    The reverse inequality is obvious.

    \item[\ref{int-sset-set}=\ref{int-sset-flt}] It's enough to prove that if $\supfun{f^{- 1}}
    \mathcal{Y} \sqsubseteq X$ for $\mathcal{Y} \in \mathscr{F} \Dst f$
    then exists $Y \in \up \mathcal{Y}$ such that $\langle f^{- 1}
    \rangle^{\ast} Y \sqsubseteq X$. Really let $\supfun{f^{- 1}}
    \mathcal{Y} \sqsubseteq X$. Then $\bigsqcap \langle \langle f^{- 1}
    \rangle^{\ast} \rangle^{\ast} \up \mathcal{Y} \sqsubseteq X$ and
    thus exists $Y \in \up \mathcal{Y}$ such that $\langle f^{- 1}
    \rangle^{\ast} Y \sqsubseteq X$ by properties of generalized filter bases.
  \end{description}
\end{proof}

This coincides with the customary definition of interior in topological
spaces.

\begin{prop}
  $f^{\circ \circ} = f$ for every funcoid $f$.
\end{prop}

\begin{proof}
  $\rsupfun{f^{\circ\circ}} X = \neg \neg \supfun{f}
  \neg \neg X = \supfun{f} X$.
\end{proof}

\begin{prop}\label{get-rid-interior}
  Let $g \in \mathsf{FCD} (A , B)$, $f \in \mathsf{FCD} (B ,
  C)$, $h \in \mathsf{FCD} (A , C)$ for some sets $A$. $B$, $C$.

  $g \sqsubseteq f^{\circ} \circ h \Leftrightarrow f^{- 1} \circ g \sqsubseteq
  h$, provided $f$ and $h$ are co-complete.
\end{prop}

\begin{proof}
  $g \sqsubseteq f^{\circ} \circ h \Leftrightarrow \forall X \in A : \rsupfun{ g
  } X \sqsubseteq \rsupfun{ f^{\circ} \circ h } X
  \Leftrightarrow \forall X \in A : \rsupfun{ g } X \sqsubseteq
  \rsupfun{ f^{\circ} } \rsupfun{ h } X \Leftrightarrow
  \forall X \in A : \rsupfun{ g } X \sqsubseteq \neg \rsupfun{ f
  } \neg \rsupfun{ h } X \Leftrightarrow
  \forall X \in A : \rsupfun{ g } X \asymp \rsupfun{ f } \neg \rsupfun{h} X \Leftrightarrow \forall X \in A : \rsupfun{ f^{- 1}
  } \rsupfun{ g } X \asymp \neg \rsupfun{ h
  } X \Leftrightarrow \forall X \in A : \rsupfun{ f^{- 1}
  } \rsupfun{ g } X \sqsubseteq \rsupfun{ h
  } X \Leftrightarrow \forall X \in A : \rsupfun{ f^{- 1} \circ g
  } X \sqsubseteq \rsupfun{ h } X \Leftrightarrow f^{-
  1} \circ g \sqsubseteq h$.
\end{proof}

\begin{rem}
The above theorem allows to get rid of interior funcoids (and use only ``regular'' funcoids) in some formulas.
\end{rem}


\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{cancel}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{color}

\newtheorem{theorem}{Theorem}
\begin{document}

\title{Finding correlation for acmPRS}

\maketitle

\textbf{Goals:}

\begin{itemize}
	\item Find $Var(\text{acmPRS})$
	\item Find $Cov(Y, \text{acmPRS})$
\end{itemize}

\subsection{Finding $Var(\text{acmPRS})$:}

Define
$$
\begin{aligned}
\hat{S}_i &= \sum^{m_i}_{j = 1} \hat{\beta} \mathbf{G_j} \\
\hat{S}_{acm} &= \sum^c_{i=1} n_i r_i \sqrt{\frac{h_i}{h_1}} \hat{S}_i
\end{aligned}
$$

\begin{theorem}
$E[\hat{S}_{acm}] = 0$
\end{theorem}

\begin{proof}
$$
\begin{aligned}
E[\hat{S}_{acm}] &= E[\sum^c_{i=1} n_i r_i \sqrt{\frac{h_i}{h_1}} \hat{S}_i] \\
&= \sum^c_{i=1} E[n_i r_i \sqrt{\frac{h_i}{h_1}} \hat{S}_i] \\
&= \sum^c_{i=1} n_i r_i \sqrt{\frac{h_i}{h_1}} E[\hat{S}_i] \\ \\
&\because E[\hat{S}_i] = 0 \\
&\therefore E[\hat{S}_{acm}] = 0
\end{aligned}
$$
\end{proof}

\newpage

\begin{theorem}
$Var(\hat{S}_{acm}) =\sum^c_{i=1}  \frac{m_i n^2_i r^2_i h_i}{h_1}  Var(\hat{\beta}_i) +  \sum^c_{i \neq j} n_i n_j r_i r_j \sqrt{\frac{h_i h_j}{h^2_1}} Cov(\hat{S}_i, \hat{S}_j)]$
\end{theorem}

\begin{proof}

$$
\begin{aligned}
Var(\sum^c_{i=1} n_i r_i \sqrt{\frac{h_i}{h_1}} \hat{S}_i) &= \sum^c_{i=1} Var \left( n_i r_i \sqrt{\frac{h_i}{h_1}} \hat{S}_i \right) + \sum_{i \neq j} Cov \left( n_i r_i \sqrt{\frac{h_i}{h_1}} \hat{S}_i, n_j r_j \sqrt{\frac{h_j}{h_1}} \hat{S}_j \right)
\end{aligned}
$$

\begin{equation}
\begin{aligned}
\sum^c_{i=1} Var \left( n_i r_i \sqrt{\frac{h_i}{h_1}} \hat{S}_i \right) &= \sum^c_{i=1} n_i r_i \sqrt{\frac{h_i}{h_1}}  Var(\hat{S}_i) \\
&= \sum^c_{i=1} n_i r_i \sqrt{\frac{h_i}{h_1}} m_i Var(\hat{\beta}_i)      \\
\end{aligned}
\end{equation}

\begin{equation}
\begin{aligned}
\sum_{i \neq j} Cov \left(  n_i r_i \sqrt{\frac{h_i}{h_1}} \hat{S}_i,  n_j r_j \sqrt{\frac{h_j}{h_1}} \hat{S}_j \right) &= \scriptstyle \sum_{i \neq j} E \left[ \left( n_i r_i \sqrt{\frac{h_i}{h_1}} \hat{S}_i \right), \left( n_j r_j \sqrt{\frac{h_j}{h_1}} \hat{S}_j  \right)  \right] + \scriptscriptstyle \cancelto{0}{E \left[ \sum^c_{i=1} n_i r_i \sqrt{\frac{h_i}{h_1}}] \hat{S}_i \right]} \cancelto{0}{E \left[ \sum^c_{j=1} n_j r_j \sqrt{\frac{h_j}{h_1}} \hat{S}_j \right]} \\
&= \sum_{i \neq j} n_i n_j r_i r_j \sqrt{\frac{h_i h_j}{h^2_1}} E[\hat{S}_i \hat{S}_j]\\
&= \sum_{i \neq j} n_i n_j r_i r_j \sqrt{\frac{h_i h_j}{h^2_1}} Cov \left( \hat{S}_i, \hat{S}_j \right) \\
\end{aligned}
\end{equation}

The above is because

$$
\begin{aligned}
Cov( \hat{S}_i, \hat{S}_j) &= E \left[ \hat{S}_i \hat{S}_j \right] + \cancelto{0}{E[ \hat{S}_i]} + \cancelto{0}{E[ \hat{S}_j ]} \\
&=  E \left[ \hat{S}_i \hat{S}_j \right]
\end{aligned}
$$

Combining (1) and (2):

$$ Var(\hat{S}_{acm}) =\sum^c_{i=1}  \frac{m_i n^2_i r^2_i h_i}{h_1}  Var(\hat{\beta}_i) +  \sum^c_{i \neq j} n_i n_j r_i r_j \sqrt{\frac{h_i h_j}{h^2_1}} Cov(\hat{S}_i, \hat{S}_j)] $$

\end{proof}

\newpage

\begin{theorem}
$Cov(Y, \text{acmPRS}) = \frac{1}{c} \sum^c_{i=1} n_i r_i \sqrt{\frac{h_i}{h_1}} m_i Cov(\hat{\beta}_i, \beta_{Y})$
\end{theorem}

\begin{proof}

$$
\begin{aligned}
\text{Cov}(Y, \text{acmPRS}) &= E[Y \text{acmPRS}] + \cancelto{0}{E[Y]} + \cancelto{0}{E[\text{acmPRS}]} \\
&= E \left[ \left( \sum^m_{j=1} \beta_{j Y} G_i \right) \left( \sum^c_{i=1} n_i r_i \sqrt{\frac{h_i}{h_1}} \sum^m_{j=1} \hat{\beta}_{j i} G_j \right) \right]
\end{aligned}
$$

\textcolor{red}{I'm really not sure if I'm allowed to do this.}

$$
\begin{aligned}
E \left[ \left( \sum^m_{j=1} \beta_{j Y} G_i \right) \left( \sum^c_{i=1} n_i r_i \sqrt{\frac{h_i}{h_1}} \sum^m_{j=1} \hat{\beta}_{j i} G_j \right) \right] &= E \left[ \sum^c_{i=1} n_i r_i \sqrt{\frac{h_i}{h_1}} \left[ \sum^{m_i} \beta_j G_j \right] \frac{1}{c} \left[ \sum^{m_Y} \beta_{jY} G_j \right] \right]
\end{aligned}
$$

Here I've brought the $Y$ score inside the summation with a $\frac{1}{c}$ coefficient.

$$
\begin{aligned}
&= \frac{1}{c} \sum^c_{i=1} \left[ n_i r_i \sqrt{\frac{h_i}{h_1}} E \left[    \sum^{m_i} \beta_j G_j \sum^{m_Y} \beta_{jY} G_j \right] \right]
\end{aligned}
$$

And since by equation (7) in power and predicitve accuracy: $ E \left[ \sum^{m_i} \beta_j G_j \sum^{m_Y} \beta_{jY} G_j \right] = m \text{Cov} (\hat{\beta}_i, \beta_Y)$

Then
$$Cov(Y, \text{acmPRS}) = \frac{1}{c} \sum^c_{i=1} n_i r_i \sqrt{\frac{h_i}{h_1}} m_i Cov(\hat{\beta}_i, \beta_{Y})$$

\end{proof}

\newpage

\begin{theorem}
$R^2_{Y, \text{acmPRS}} = \frac{ \frac{1}{c^2} \left( \sum^c_{i=1} n_i r_i \sqrt{\frac{h_i}{h_1}} m_i Cov(\hat{\beta}_i, \beta_{Y}) \right)^2}{ \left( \sum^c_{i=1}  \frac{m_i n^2_i r^2_i h_i}{h_1}  Var(\hat{\beta}_i) +  \sum^c_{i \neq j} n_i n_j r_i r_j \sqrt{\frac{h_i h_j}{h^2_1}} Cov(\hat{S}_i, \hat{S}_j)] \right) \left( \sigma^2_{g} + \sigma^2_{e} \right)}$
\end{theorem}

\begin{proof}

$$
\begin{aligned}
R^2_{X, Y} = \frac{Cov(X,Y)^2}{Var(X)Var(Y)}
\end{aligned}
$$

Sub in equations in theorems (2) and (3).

\end{proof}

\end{document}