# MAPLE ASSIGNMENT 2
# INVERSE FUNCTIONS
# Graphically an inverse function is the mirror image of the original
# function across the 45 degree line..Note the use of the  notation [ ]
# to draw multiple plots and
# the need to specify the scale on the y-axis to get this plot to look
# right.
> g:=x->x;

                             g := x -> x

> plot(g(x),x=.1..2);

> plot([exp(x),g(x)],x=.1..2);

> plot([ln(x),exp(x),g(x)],x=.1..2,y=.1..2);

# The inverse function of sin(x) is called arcsin(x). Why is [-1,1] the
# largest interval about 0 that arcsin(x) can 
# be defined on? Use that interval as your scale for x. Then do the
# mirror image diagam, change the type of the axes if you wish and make
# sure you understand which curve is which.
> plot(arcsin(x),x=-1..1);

> plot([sin(x),arcsin(x),g(x)],x=-Pi/2..Pi/2,y=-Pi/2..Pi/2);

# COMPOUNDING AND DISCOUNTING
> FV:=(m,t,r)->1000*(1+r/m)^(m*t);

                                                 (m t)
                FV := (m, t, r) -> 1000 (1 + r/m)

> FV(2,3,.06);

                             1194.052297

# Calculate some future values of your own using different values of m,
# t, r.  You can even change the 
# present value of $1000 if you wish by editing and reexecuting the
# input line defining FV.
> FVc:=(t,r)->1000*exp(r*t);

                    FVc := (t, r) -> 1000 exp(t r)

# This is the formula for continuous compounding.
> FVc(3,.06);

                             1197.217363

# If your financial institution offered continuous compounding on your
# savings rather than annual compounding would you be better off?  The
# answer is probably yes but
# you should compare the interest rates used for the two types of
# compounding.  The next
# calculation shows what continuous interest rate would pay exactly the
# same amount of interst over one year as annual compounding at an
# interest rate of 6%. 
> solve(FVc(1,r)=FV(1,1,.06),r);

                             .05826890812

# In class it was claimed that as n gets larger and larger, (1+1/n)^n
# gets closer and closer to the number e.  Here are two ways to check
# this out. In the first way use
# PG UP & PG DN to see all the numbers or click on the scroll bar to
# move the page up and down.
> evalf(exp(1));

                             2.718281828

> seq(evalf((1+1/n)^n),n=1..100);

2., 2.250000000, 2.370370370, 2.441406250, 2.488320000, 2.521626372,

    2.546499697, 2.565784514, 2.581174792, 2.593742460, 2.604199012,

    2.613035290, 2.620600888, 2.627151556, 2.632878718, 2.637928497,

    2.642414375, 2.646425821, 2.650034327, 2.653297705, 2.656263214,

    2.658969859, 2.661450119, 2.663731258, 2.665836331, 2.667784967,

    2.669593978, 2.671277853, 2.672849144, 2.674318776, 2.675696306,

    2.676990129, 2.678207651, 2.679355428, 2.680439286, 2.681464420,

    2.682435477, 2.683356626, 2.684231618, 2.685063838, 2.685856348,

    2.686611922, 2.687333085, 2.688022135, 2.688681171, 2.689312111,

    2.689916715, 2.690496599, 2.691053247, 2.691588029, 2.692102209,

    2.692596954, 2.693073347, 2.693532389, 2.693975012, 2.694402081,

    2.694814402, 2.695212726, 2.695597753, 2.695970139, 2.696330496,

    2.696679398, 2.697017382, 2.697344953, 2.697662584, 2.697970722,

    2.698269786, 2.698560171, 2.698842248, 2.699116371, 2.699382870,

    2.699642059, 2.699894235, 2.700139679, 2.700378656, 2.700611420,

    2.700838208, 2.701059249, 2.701274758, 2.701484941, 2.701689991,

    2.701890096, 2.702085431, 2.702276166, 2.702462461, 2.702644469,

    2.702822336, 2.702996202, 2.703166202, 2.703332461, 2.703495103,

    2.703654244, 2.703809996, 2.703962466, 2.704111756, 2.704257966,

    2.704401190, 2.704541517, 2.704679036, 2.704813829

> evalf(exp(1));

                             2.718281828

# The other method is to let Maple calculate the limit for you. Here x
# =(1/n)
> limit((1+x)^(1/x),x=0);

                                exp(1)

> evalf(");

                             2.718281828

# Suppose the value of  the logs that can be harvested from a piece of
# land will be $1000ln(.5t +1) if the land is logged t years from now.
# The function PV defined below  gives the present value of the sum of
# money that would be received t years from now assuming a 6% interest
# rate and continuous discounting .
> PV:= t->1000*ln(.5*t+1.)*exp(-.06*t);

              PV := t -> 1000 ln(.5 t + 1.) exp(-.06 t)

> [PV(0.),PV(5.),PV(10.),PV(15.)];

              [0, 928.0696329, 983.3384457, 870.0859716]

# Which of these 4 choices of cutting date is best. Next, we can plot PV
# to do better than this. Click 
# on the point on the screen where PV is largest.
> plot(PV(t),t=0..20);

# You can modify the definition of PV so that discrete discounting is
# used rather than continuous discounting. Does this change the best
# cutting date much?
# CONTINUITY AND DISCONTINUITY
# Here you can view a continuous total cost curve.
> C:=y->y^3-4*y^2+6*y;

                                 3      2
                      C := y -> y  - 4 y  + 6 y

> plot(C(y),y=0..3);

# Two simple built-in functions with discontinuiities. However, Maple
# will produce a contiuous approximation to the plot unless it is told
# not to. The next line may help you understand what these two functions
# are.
> [frac(2.5),floor(2.5)];

                               [.5, 2]

#  
> plot(frac(x),x=0..5);

> plot(frac(x),x=0..5,discont=true);

> plot(floor(x),x=0..5,discont=true);

> plot(frac(x)+floor(x),x=0..5);

# f(x)=(1-exp(-x))^(-1) is another example of a jump discontinuity but
# Maple needs to be tricked to draw it. The plot looks better if you
# choose on the axes menu an option other than normal such as the option
# none.  To understand this example think about the limit of exp(-1/x))
# as x tends to zero from the right and from the left.  If you wish you
# can get Maple to compute these limits for you as was illustrated
# earlier.  Add  ,right or ,left  after x=0 in the limit command.
> f:=x->1/(1-exp(-1/x));

                                       1
                       f := x -> --------------
                                 1 - exp(- 1/x)

> plot([[x,f(x),x=-1..0],[x,f(x),x=0..1]]);

# The command plot([[f(x),g(x),x=a..b]) is used to draw a parametric
# plot, that is the curve (f(x),g(x)) is sketched as x varies over the
# specified range. Above a pair of parametric plots is used to sketch
# the two parts of f(x) on the same plot. Maple does not handle the plot
# of f(x) as a single plot.
# The next example is one where the limit of f(x) as x tends to zero
# does not exist.  Why not?
> plot(sin(1/x),x=-2/Pi..2/Pi);

# A modification of the above example is continuous at x=0.
> plot(x*sin(1/x),x=-2/Pi..2/Pi);

# The last example is based on the normal curve.  It is continuous and
# shows how to get a sharp spike.
> plot(exp(-x^2*1000),x=-1..1);

# INCOME SUPPORT PLAN (Exercise 6, p.120)
# Plan B can be plotted as a parametric plot rather than by defining a
# function to represent the plan.
> plot([x,6000+.6*x,x=0..10000]);

# Plan A has 3 separate schedules each of which can be plotted in the
# same way.  To get them all in 
# the same plot enclose the list in [] and separate the description of
# each parametric plot by commas.The axes can be moved slightly by
# choosing axes=boxed or axes=framed in the axes menu.
> plot([[0,y,y=0..6000],[x,x,x=0..6000],[x,x+.8*(x-6000),x=6000..10000]]
> );

# Then to get both plans in the same plot and to see which is best for
# which income earners
> plot({[0,y,y=0..6000],[x,x,x=0..6000],[x,x+.8*(x-6000),x=6000..10000],
> [x,6000+.6*x,x=0..10000]});# 
# If you wish to print any of the graphics, execute the following
# command. Then reexecute your plot. It will appear in a window from
# which it can be sent to the printer. Lines can be made thicker by
# using the line width option on the style menu.
> plotsetup(window);
plotsetup: warning unknown device
> 
