# Lab Project II
# Two identical  jars of boiling water, labeled A and B,  stand beside
# two identical jars of ice water , labeled C and D, in a room whose
# temperature remains constant.   The contents of jars A and C are
# immediately mixed. Jars B and D are kept separate for a few minutes
# and then mixed.  How will the temperatures of the two mixtures
# compare?  One school of thought says that the AC mixture  will be
# hotter because  jar D, being very hot will lose its heat much more
# rapidly than the cooler AC mixture and the result will be that more
# heat is lost  by B alone than by the AC misture. Another says that the
# hot water from A and  the cold water from C  will act independently,
# just like the separate portions in B and D  and therefore the mistures
# will be the same temperature.  
# 
# Run a number of (theoretical) experiments, varying the  temperatures
# of the room and water,  the quantities of hot and cold water, and the
# times.   Prepare a report on the experiments, complete with  an
# explanation of the calculations (the theory) ,  a separate section of
# results and  a third of interpretation of the results relative to the
# original question.  In a final section provide a theoretical
# explanation of the results of the experiments.
# 
# Alternative Formulation
# 
# Ms. Karen Heavin suggests the following alternative statement for the
# lab. You may report on the original, this, or your own version.
# 
# There were once three friends, Carl, Paul,  and John.  In an attempt
# to survive the last two weeks of the semester they had begun a nightly
# ritual of studying into the wee hours of the morning, replacing sleep
# with coffee.  During one of their sessions, after consuming about 15
# cups of coffee each, Carl decided to go run around the block to
# control the  shaking of his limbs from too much coffee.  Just as he
# was about to get up, John inadvertently poured Carl a full cup of
# fresh coffee.  Carl said not to worry about it he would drink it when
# he got back.  John then offered to put cream in the coffee so it would
# be "just right" when Carl got back from his run.  Carl objected
# strenuously to this stating that the creme would cause his coffee to
# be too cold when he got back.  Upon hearing this Paul assured Carl his
# coffee would not be any colder than if he left it alone and poured the
# cream in when he got back. John felt Paul was in error and told him
# so.
# 
# Anyway, Carl started to prepare  for his run  but fell asleep as he
# sat on his bed to put on his running shoes.  John and Paul argued all
# night over the  timing the cream pouring (rather than studying
# calculus).
# 
# The next morning Carl  found his friends  still arguing.  However,
# after a nights sleep he could think straight.  He  drank the cold cup
# of coffee, then quickly put the argument to rest by modeling the
# problem with  Newton's law of cooling (or whatever), doing some
# exprimental calculations, looking at some graphs  and then explaining
# the results.  Then  Carl went  off to school while John and Paul fell
# asleep.
# 
# 
# 
# GETTING STARTED:   One will need to assume that the constant, k , in
# Newton's law of cooling is the same for all aspects of the problem. In
# addition one will need to assume that the temperature of a mixture of
# two containers of water will be the weighted average of the
# temperatures of the two components. 
# 
# The following takes one through a related problem and contains all of
# the Maple commands and ideas one might need.
# 
# Problem : Two cups of soup, the first at 90 C and the second at 100 C
# are put in a room where the temp is maintained at 20 C.  The first cup
# cooled from 90 C to 60 C after 10 minutes, at which time the second
# cup is put in a freezer at -5 C.  Assume Newton's law of cooling and
# answer the following questions.
#  
# (a)  Express the temperature of each cup as a function of time, and
# draw their graphs.
# 
# (b) How much longer will it take the two cups to reach the same
# temperature?
# 
# Solution:  Assuming Newton's Law of cooling,  the rate at which each
# cup cools is proportional to the difference between the ambient
# temperature and the temperature of the soup in the cup.   The
# differential equation for each cup looks like this: 
> restart;
> Diff(f(t),t) = k*(f(t)-20);

                       d
                       -- f(t) = k (f(t) - 20)
                       dt

#  This is a separable differential equation, whose solution can be
# written in the
# form  
> T := 20 + (T0-20)*exp(k*t);
# 

                     T := 20 + (T0 - 20) exp(k t)

# where T = T0  at t=0  and k is determined by the information given
# that the first cup cools to 60 C in 10 minutes (i.e.  T=60  at  t=10).
# 
# So if we denote the temperature of the first cup after t minutes by f 
# then
> f := subs(T0=90,T);

                        f := 20 + 70 exp(k t)

>  k :=solve(subs(t=10,f) =60,k);

                          k := 1/10 ln(4/7)

> f := unapply(f,t);   

                f := t -> 20 + 70 exp(1/10 ln(4/7) t)

# Assume that this value of k is also valid for the second cup.  (Why
# shouldn't it be? They are both soup.)  So the second cup's temperature
# is given by
# 
> g := subs(T0=100,T);

                   g := 20 + 80 exp(1/10 ln(4/7) t)

> g  := unapply(g,t);

                g := t -> 20 + 80 exp(1/10 ln(4/7) t)

# 
# for the first 10 minutes.  From that time on, the second cup's
# temperature is given by 
# 
> h := t -> -5 + (itemp - (-5))*exp(k*t);

                 h := t -> -5 + (itemp + 5) exp(k t)

> 
# 
# where itemp is the temperature that the 2nd cup would start at in
# order for it to cool to g(10) degrees C if it were in the freezer from
# the start.  So itemp satisfies the equation
# 
> eq := -5 + (itemp +5)*exp(k*10) = g(10); 

                   eq := - 15/7 + 4/7 itemp = 460/7

>    
# 
# Solving for itemp,
# 
> itemp := solve(eq,itemp);

                            itemp := 475/4

>         
# 
# Now plot the two temperature curves.
# 
> cup1 := [t,f(t),t=0..20]; 

        cup1 := [t, 20 + 70 exp(1/10 ln(4/7) t), t = 0 .. 20]

> cup2 := [t,g(t),t=0..10],[t,h(t),t=10..20];

cup2 := [t, 20 + 80 exp(1/10 ln(4/7) t), t = 0 .. 10],

    [t, -5 + 495/4 exp(1/10 ln(4/7) t), t = 10 .. 20]

> plot( {cup1,cup2},color=black );

> 
# 
# The cups are at the same temperature before another 5 minutes pass.
# 
> etime := solve(f(t)=h(t),t);

                                        20
                                     ln(--)
                                        43
                         etime := 10 -------
                                     ln(4/7)

>  `Cups are same temp at t=`,evalf(etime),` minutes`;            

           Cups are same temp at t=, 13.67845330,  minutes

# 
# At that time the common temperature is 
# 
> f(etime);

                                 2260
                                 ----
                                  43

> evalf(f(etime)),` degrees celsius.`;

                    52.55813953,  degrees celsius.

>