Re: Differentiation and Polynomial questions

• To: mathgroup at smc.vnet.net
• Subject: [mg20764] Re: Differentiation and Polynomial questions
• From: David Pearson <david.pearson at mail.nerc-essc.ac.uk>
• Date: Thu, 11 Nov 1999 00:22:42 -0500
• Organization: ESSC
• References: <805vjq\$ddu@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hi,

Danny Mathews wrote:

> My Calculus instructor loves piece-wise functions.  Any info on plotting

An easy way is to plot all the pieces seperately, then show
them all at once with Show, like this:

In[7]:= Plot[Sin[x],{x,1,2}]

#  #   #  #   #  #   #  #   #   #  #   #  #   #  #   #  #   #   #
#   #
###########################################################################
#            1.2           1#####        1.6     ####   1.8
2
#                        ####                       ####
0.975#                      ###                             ###
#                    ###                                 ###
#                  ###                                     ###
#                 ##                                         ###
0.95 #               ###                                            ##
#             ###                                               ###
#            ##                                                   ##
0.925#           ##                                                     ###
#         ###
##
#        ##
##
#       ##
0.9 #      ##
#     ##
#    ##
0.875#   ##
#  ##
# ##
###
0.85 ##
#

Out[7]= -Graphics-

In[8]:= Plot[Cos[x],{x,2,3}]

#
##
####
#  ###
#    ###
-0.5#      ###
#        ####
#           ###
#             ###
-0.6#               ####
#                  ###
#                    ####
-0.7#                       ###
#                         ####
#                            ####
#                               ####
-0.8#                                  ####
#                                     ####
#                                        #####
#                                            #####
-0.9#                                                #####
#                                                    #######
#                                                          #######
#  #   #   #  #   #  #   #   #  #   #  #   #   #  #   #  #   #   ########
############################################################################
2.2            2.4           2.6           2.8
3

Out[8]= -Graphics-

In[9]:= Show[%,%%]

#              ###########
1#   ############         ############
#####
#
#
#
0.5#
#
#
#
#
#  #   #   #  #   #  #   #   #  #   #  #   #   #  #   #  #   #   #
#   #
############################################################################
#                1.5                2                2.5
3
#
#
#                                   ##
#                                    ####
-0.5#                                       #####
#                                           ######
#                                                ######
#                                                     #######
#                                                           ###########
-1#
###

Out[9]= -Graphics-

If you want to join the segments with vertical lines, use the UnitStep
function, whicc is zero for x<0, otherwise 1. You probably have to load
it through the DiracDelta package, i.e. type

<Calculus`DiracDelta`

Then you can plot a section of a function between 2 and 4.5 (for example)
by plotting (UnitStep[x-2] - UnitStep[x-4.5]) * f[x] , which includes
vertical lines at the ends of the section of the function.  If you
plotted

(UnitStep[x-2]-UnitStep[x-4.5])*f[x]+(UnitStep[x-4.5]-UnitStep[x-7])*g[x]

you would get a segment of f[x] and one of g[x], joined with a vertical
line.

-David.

--
David Pearson,              Phone: +44 (0)118  9318741
ESSC,                       Fax:   +44 (0)118  9316413
University of Reading,      Email: dwcp at mail.nerc-essc.ac.uk