The Slope of a Function

Let us take another look at the function graph in figure~#figfuncint#31699>. external ~<#31701#>This subsection introduces the notion of derivative in a computational manner. It relies on a good understanding of lines (as functions) and a basic understanding of functions and function graphs. The exercises are simpler than the concepts.<#31701#> For many problems, we need to be able to draw a line that has the same slope as some curve at a certain point. Indeed, computing the slope is often the true goal. In economic problems, the slope is the growth rate of a company if the curve represents the income over time. In a physcial problem, the curve could represent the acceleration of some object; its slope, at any point, is then the current velocity of the object. Determining the slope of some function f at some point x means to <#31702#>differentiate<#31702#> the function. The differential operator (also called a functional) returns a function f' (pronounced ``f prime''). It tells us for any x what the slope of f is at that point. Computing f' is complicated, so it is again a good task for a computer program. The program consumes some function f and produces f'.
\ \ \ <#65961#> external <#65961#>
<#31704#>Figure: The graph of some function<#31704#>
To design a ``differentiator'' we must study how we could construct lines that have the same slope as a curve. In principle, such a line touches the curve at just that point. But suppose we relax this constraint for a moment and look at straight lines that intersect the curve <#31706#> close to<#31706#> the point of interest. We pick two points that are equally far away from <#31707#>x<#31707#>, say, #tex2html_wrap_inline73444# and #tex2html_wrap_inline73446#; the constant #tex2html_wrap_inline73448#, pronounced epsilon, represents some small distance. Using the two corresponding points on the curve, we can determine a straight line that has the proper slope. The situation is sketched in figure~#figfuncdiff#31711>. If the point of interest has coordinate <#31712#>x<#31712#>, the two points are #tex2html_wrap_inline73450# and #tex2html_wrap_inline73452#. Hence, the slope of the line is

#displaymath73454#

that is, the difference between the height of the right point and the left point divided by their horizontal distance. Determining the line from the slope and one of the points or even from two points is an exercise.
<#31723#>Exercise 23.5.1<#31723#> The equation for a line is

#displaymath73456#

By now, it is straightforward to translate this equation into Scheme:

<#31729#>(d<#31729#><#31730#>efine<#31730#> <#31731#>(y<#31731#> <#31732#>x)<#31732#>
  <#31733#>(+<#31733#> <#31734#>(*<#31734#> <#31735#>a<#31735#> <#31736#>x)<#31736#> <#31737#>b))<#31737#> 
To obtain a concrete line we must replace <#65962#><#31741#>a<#31741#><#65962#> and <#65963#><#31742#>b<#31742#><#65963#> with numbers. The teachpack <#31743#>graphing.ss<#31743#> provides two operations for drawing lines: <#65964#><#31744#>graph-line<#31744#><#65964#>. The operation consumes a line like <#65965#><#31745#>y<#31745#><#65965#> and a color, say, <#65966#><#31746#>RED<#31746#><#65966#>. Use <#65967#><#31747#>graph-line<#31747#><#65967#> to draw the graphs of the following lines:
  1. #tex2html_wrap_inline73458#
  2. #tex2html_wrap_inline73460#
  3. #tex2html_wrap_inline73462#
  4. #tex2html_wrap_inline73464#
  5. #tex2html_wrap_inline73466#
~ external Solution<#65968#><#65968#> <#31755#>Exercise 23.5.2<#31755#> It is a standard mathematical exercise to develop the equation for a line from a point on the line and its slope. Look up the method in your mathematics book. Then develop the function <#65969#><#31757#>line-from-point+slope<#31757#><#65969#>, which implements the method. The function consumes a <#65970#><#31758#>posn<#31758#><#65970#> (the point) and a number (the slope). It produces a function that represents the line in the spirit of exercise~#extangent1#31759>. Testing a function-producing function like <#65971#><#31760#>line-from-point+slope<#31760#><#65971#> can be done in two ways. Suppose we apply the function to (0,4) and 1. The result should be line #tex2html_wrap_inline73470# from exercise~#extangent1#31761>. To check this, we can either apply the result of
<#31766#>(line-from-point+slope<#31766#> <#31767#>(make-posn<#31767#> <#31768#>0<#31768#> <#31769#>4)<#31769#> <#31770#>1)<#31770#>
to some numbers, or we can draw the result using the operations in <#31774#>graphing.ss<#31774#>. In the first case, we must use #tex2html_wrap_inline73472# to compare outputs; in the second case we can draw the result in one color and the hand-constructed line in a different one and observe the effect.~ external Solution<#65972#><#65972#>
Once we have an intersecting line through #tex2html_wrap_inline73474# and #tex2html_wrap_inline73476#, it is basically obvious how to get a line with the proper slope. By decreasing #tex2html_wrap_inline73478# until it is (almost) indistinguishable from 0, the two intersection points move closer and closer until they are one, namely, (x,f(x)), the point for which we wish to know the slope.
<#31788#>Exercise 23.5.3<#31788#> Use the operation <#65974#><#31790#>graph-fun<#31790#><#65974#> in the teachpack <#31791#>graphing.ss<#31791#> to draw the mathematical function

#displaymath73484#

The operation works just like <#65975#><#31792#>draw-line<#31792#><#65975#> (see exercise~#extangent1#31793>. Suppose we wish to determine the slope at x = 2. Pick an #tex2html_wrap_inline73488# and determine the slope of the line that goes through #tex2html_wrap_inline73490# and #tex2html_wrap_inline73492# with the above formula. Compute the line with <#65976#><#31797#>line-from-point+slope<#31797#><#65976#> from exercise~#extangent2#31798> and use <#65977#><#31799#>draw-line<#31799#><#65977#> to draw it into the same coordinate system as <#65978#><#31800#>y<#31800#><#65978#>. Repeat the process with #tex2html_wrap_inline73494# and then with #tex2html_wrap_inline73496#.~ external Solution<#65981#><#65981#>
If our goal is to define the differential operator as a Scheme function, we can approximate it by setting #tex2html_wrap_inline73498# to a small number and by translating the mathematical formula into a Scheme expression: external ~<#71433#>We use an unusal name here: <#65982#><#31812#>d/dx<#31812#><#65982#>. As we have mentioned before, Scheme permits programmers to put many more symbols into a variable name than other languages. Since mathematics uses

#displaymath73500#

as the name for the differential operator, we choose a name that is as close as possible.<#71433#>

<#71434#>;; <#65985#><#31819#>d/dx<#31819#> <#31820#>:<#31820#> <#31821#>(num<#31821#> <#31822#><#31822#><#31823#>-;SPMgt;<#31823#><#31824#><#31824#> <#31825#>num)<#31825#> <#31826#><#31826#><#31827#>-;SPMgt;<#31827#><#31828#><#31828#> <#31829#>(num<#31829#> <#31830#><#31830#><#31831#>-;SPMgt;<#31831#><#31832#><#31832#> <#31833#>num)<#31833#><#65985#><#71434#>
<#71435#>;; to compute the derivative function of <#65986#><#31834#>f<#31834#><#65986#> numerically<#71435#> 
<#31835#>(d<#31835#><#31836#>efine<#31836#> <#31837#>(d/dx<#31837#> <#31838#>f)<#31838#> 
  <#31839#>(l<#31839#><#31840#>ocal<#31840#> <#31841#>(<#31841#><#31842#>(d<#31842#><#31843#>efine<#31843#> <#31844#>(fprime<#31844#> <#31845#>x)<#31845#> 
            <#31846#>(/<#31846#> <#31847#>(-<#31847#> <#31848#>(f<#31848#> <#31849#>(+<#31849#> <#31850#>x<#31850#> <#65987#>#tex2html_wrap_inline73502#<#65987#><#31852#>))<#31852#> <#31853#>(f<#31853#> <#31854#>(-<#31854#> <#31855#>x<#31855#> <#65988#>#tex2html_wrap_inline73504#<#65988#><#31857#>)))<#31857#> 
               <#31858#>(*<#31858#> <#31859#>2<#31859#> <#65989#>#tex2html_wrap_inline73506#<#65989#><#31861#>)))<#31861#> 
          <#31862#>(define<#31862#> <#65990#>#tex2html_wrap_inline73508#<#65990#> <#31864#>...))<#31864#> 
    <#31865#>fprime))<#31865#> 
explain the right-hand side of arrow As mentioned in the introduction to this section, the differential operator computes the function f' from some function f. The former computes the slope of f for any <#31869#>x<#31869#>. For straight lines, the slope is always known. Hence, a function that represents a straight line is an ideal test case for <#65991#><#31870#>d/dx<#31870#><#65991#>. Let us consider
<#31875#>(d<#31875#><#31876#>efine<#31876#> <#31877#>(a-line<#31877#> <#31878#>x)<#31878#>
  <#31879#>(+<#31879#> <#31880#>(*<#31880#> <#31881#>3<#31881#> <#31882#>x)<#31882#> <#31883#>1))<#31883#> 
The evaluation of <#65992#><#31887#>(d/dx<#31887#>\ <#31888#>a-line)<#31888#><#65992#> proceeds as follows:
  <#31893#>(d/dx<#31893#> <#31894#>a-line)<#31894#>
<#31895#>=<#31895#> <#31896#>(l<#31896#><#31897#>ocal<#31897#> <#31898#>(<#31898#><#31899#>(d<#31899#><#31900#>efine<#31900#> <#31901#>(fprime<#31901#> <#31902#>x)<#31902#> 
            <#31903#>(/<#31903#> <#31904#>(-<#31904#> <#31905#>(a-line<#31905#> <#31906#>(+<#31906#> <#31907#>x<#31907#> <#65993#>#tex2html_wrap_inline73516#<#65993#><#31909#>))<#31909#> <#31910#>(a-line<#31910#> <#31911#>(-<#31911#> <#31912#>x<#31912#> <#65994#>#tex2html_wrap_inline73518#<#65994#><#31914#>)))<#31914#> 
               <#31915#>(*<#31915#> <#31916#>2<#31916#> <#65995#>#tex2html_wrap_inline73520#<#65995#><#31918#>)))<#31918#> 
          <#31919#>(define<#31919#> <#65996#>#tex2html_wrap_inline73522#<#65996#> <#31921#>...))<#31921#> 
    <#31922#>fprime)<#31922#> 
<#31923#>=<#31923#> <#31924#>(d<#31924#><#31925#>efine<#31925#> <#31926#>(fprime<#31926#> <#31927#>x)<#31927#> 
    <#31928#>(/<#31928#> <#31929#>(-<#31929#> <#31930#>(a-line<#31930#> <#31931#>(+<#31931#> <#31932#>x<#31932#> <#65997#>#tex2html_wrap_inline73524#<#65997#><#31934#>))<#31934#> <#31935#>(a-line<#31935#> <#31936#>(-<#31936#> <#31937#>x<#31937#> <#65998#>#tex2html_wrap_inline73526#<#65998#><#31939#>)))<#31939#> 
       <#31940#>(*<#31940#> <#31941#>2<#31941#> <#65999#>#tex2html_wrap_inline73528#<#65999#><#31943#>)))<#31943#> 
  <#31944#>(define<#31944#> <#66000#>#tex2html_wrap_inline73530#<#66000#> <#31946#>...)<#31946#> 
  <#31947#>fprime<#31947#> 
Now, if we think of <#71436#><#31951#>(+<#31951#>\ <#31952#>x<#31952#>\ <#66001#>#tex2html_wrap_inline73532#<#66001#><#31954#>)<#31954#><#71436#> and <#71437#><#31955#>(-<#31955#>\ <#31956#>x<#31956#>\ <#66002#>#tex2html_wrap_inline73534#<#66002#><#31958#>)<#31958#><#71437#> as numbers, we can evaluate the application of <#66003#><#31959#>a-line<#31959#><#66003#> in the definition of <#66004#><#31960#>fprime<#31960#><#66004#>:
  <#31968#>(d<#31968#><#31969#>efine<#31969#> <#31970#>(fprime<#31970#> <#31971#>x)<#31971#>
    <#31972#>(/<#31972#> <#31973#>(-<#31973#> <#31974#>(+<#31974#> <#31975#>(*<#31975#> <#31976#>3<#31976#> <#31977#>(+<#31977#> <#31978#>x<#31978#> <#66007#>#tex2html_wrap_inline73538#<#66007#><#31980#>))<#31980#> <#31981#>1)<#31981#> <#31982#>(+<#31982#> <#31983#>(*<#31983#> <#31984#>3<#31984#> <#31985#>(-<#31985#> <#31986#>x<#31986#> <#66008#>#tex2html_wrap_inline73540#<#66008#><#31988#>))<#31988#> <#31989#>1))<#31989#> 
       <#31990#>(*<#31990#> <#31991#>2<#31991#> <#66009#>#tex2html_wrap_inline73542#<#66009#><#31993#>)))<#31993#> 
<#31994#>=<#31994#> <#31995#>(d<#31995#><#31996#>efine<#31996#> <#31997#>(fprime<#31997#> <#31998#>x)<#31998#> 
    <#31999#>(/<#31999#> <#32000#>(-<#32000#> <#32001#>(*<#32001#> <#32002#>3<#32002#> <#32003#>(+<#32003#> <#32004#>x<#32004#> <#66010#>#tex2html_wrap_inline73544#<#66010#><#32006#>))<#32006#> <#32007#>(*<#32007#> <#32008#>3<#32008#> <#32009#>(-<#32009#> <#32010#>x<#32010#> <#66011#>#tex2html_wrap_inline73546#<#66011#><#32012#>)))<#32012#> 
       <#32013#>(*<#32013#> <#32014#>2<#32014#> <#66012#>#tex2html_wrap_inline73548#<#66012#><#32016#>)))<#32016#> 
<#32017#>=<#32017#> <#32018#>(d<#32018#><#32019#>efine<#32019#> <#32020#>(fprime<#32020#> <#32021#>x)<#32021#> 
    <#32022#>(/<#32022#> <#32023#>(*<#32023#> <#32024#>3<#32024#> <#32025#>(-<#32025#> <#32026#>(+<#32026#> <#32027#>x<#32027#> <#66013#>#tex2html_wrap_inline73550#<#66013#><#32029#>)<#32029#> <#32030#>(-<#32030#> <#32031#>x<#32031#> <#66014#>#tex2html_wrap_inline73552#<#66014#><#32033#>)))<#32033#> 
       <#32034#>(*<#32034#> <#32035#>2<#32035#> <#66015#>#tex2html_wrap_inline73554#<#66015#><#32037#>)))<#32037#> 
<#32038#>=<#32038#> <#32039#>(d<#32039#><#32040#>efine<#32040#> <#32041#>(fprime<#32041#> <#32042#>x)<#32042#> 
    <#32043#>(/<#32043#> <#32044#>(*<#32044#> <#32045#>3<#32045#> <#32046#>(*<#32046#> <#32047#>2<#32047#> <#66016#>#tex2html_wrap_inline73556#<#66016#><#32049#>))<#32049#> 
       <#32050#>(*<#32050#> <#32051#>2<#32051#> <#66017#>#tex2html_wrap_inline73558#<#66017#><#32053#>)))<#32053#> 
<#32054#>=<#32054#> <#32055#>(d<#32055#><#32056#>efine<#32056#> <#32057#>(fprime<#32057#> <#32058#>x)<#32058#> 
    <#32059#>3)<#32059#> 
In other words, the result of <#66018#><#32063#>(d/dx<#32063#>\ <#32064#>a-line)<#32064#><#66018#> always returns 3, which is the slope of <#66019#><#32065#>a-line<#32065#><#66019#>. In short, we not only got a close approximation because #tex2html_wrap_inline73560# is small, we actually got the correct answer. In general, however, the answer will be depend on <#71439#><#66020#>#tex2html_wrap_inline73562#<#66020#><#71439#> and will not be precise.
<#32070#>Exercise 23.5.4<#32070#> Pick a small #tex2html_wrap_inline73564# and use <#66021#><#32073#>d/dx<#32073#><#66021#> to compute the slope of

#displaymath73566#

at x = 2. How does the result compare with your calculation in exercise~#extangent3#32074>?~ external Solution<#66022#><#66022#> <#32080#>Exercise 23.5.5<#32080#> Develop the function <#66023#><#32082#>line-from-two-points<#32082#><#66023#>. It consumes two points <#66024#><#32083#>p1<#32083#><#66024#> and <#66025#><#32084#>p2<#32084#><#66025#>. Its result is a Scheme function that represents the line through <#66026#><#32085#>p1<#32085#><#66026#> and <#66027#><#32086#>p2<#32086#><#66027#>. Question: Are there any situations for which this function may fail to compute a function? If so, refine the definition to produce a proper error message in this case.~ external Solution<#66028#><#66028#> <#32092#>Exercise 23.5.6<#32092#> Compute the slope of the following function

<#32098#>(d<#32098#><#32099#>efine<#32099#> <#32100#>(f<#32100#> <#32101#>x)<#32101#> 
  <#32102#>(+<#32102#> <#32103#>(*<#32103#> <#32104#>1/60<#32104#> <#32105#>(*<#32105#> <#32106#>x<#32106#> <#32107#>x<#32107#> <#32108#>x))<#32108#> 
     <#32109#>(*<#32109#> <#32110#>-1/10<#32110#> <#32111#>(*<#32111#> <#32112#>x<#32112#> <#32113#>x))<#32113#> 
     <#32114#>5))<#32114#> 
at x = 4. Set #tex2html_wrap_inline73572# to <#66029#><#32119#>2<#32119#><#66029#>, <#66030#><#32120#>1<#32120#><#66030#>, <#66031#><#32121#>.5<#32121#><#66031#>. Try the same for some other value of <#66032#><#32122#>x<#32122#><#66032#>.~ external Solution<#66033#><#66033#>