Calculus/Approximating Values of Functions

From testwiki
Jump to navigation Jump to search

Template:Calculus/Top Nav

Although many times, a value can and does have an exact representation that is and can be described by some function, it is sometimes useful to get an approximation of those values especially in many real world contexts. For example, a construction worker might need a room to be 2 feet long. However, this value is not useful because most rulers do not have a measurement for 2. Instead, workers need an approximation of the length to be able to construct a room that is 2 feet long.

Some numbers were and still are very hard to approximate, but calculus makes it easier to do so. The subfield of Numerical Analysis studies algorithms used to approximate numbers, including but not limited to the residual (how much the value is off from the true value), the level of decimal precision, and the amount of times the procedure needs to be done to reach a certain level of precision.

While this section will not be a replacement for numerical analysis (not even close), this section will hopefully introduce efficient algorithms to approximate values to surprising levels of accuracy.

Before diving into this section, Section Template:Calculus/map page already introduced a method to approximate the solution to a function using calculus as justification behind this approximation algorithm, referred to as the Bisection Method. Using calculus to approximate values should therefore not be very surprising.

Linear Approximation

Figure 1: The tangent line to the function at α approximates the f(c) quite well.


Recall one of the definitions of the derivative: it is the slope of the tangent line at a point, x=α, of the function f. Thinking about the local behavior of the function f around x=α, the tangent line can be a good approximation of the value f(c) (refer to Figure 1) if cα is small and f(c)f(α) is small.

Template:Calculus/Def

Justification: Notice the tangent line at x=α for some differentiable function f(x) is given by the following equation:

Template:Equation

where h(x) is the equation of the tangent line.

If we are trying to obtain f(c) (the true value) through the tangent line, and the distance |f(c)f(α)|=ϵ0 for all small ϵ0>0, then h(c)f(c). Therefore,

f(c)h(c)=f(α)+f(α)(cα)

Notice that for this technique to be used, it needs to be the case that

  1. f(x) is differentiable at x=α and continuous in [α,c].
  2. |cα| is small and |f(c)f(α)| is small. Otherwise, some very strange possible approximations may appear.
  3. f(x) is monotonic in [α,c]. (You will learn this more comprehensively in Section Template:Calculus/map page.)

If any one of these conditions are false, then this technique will either not work or will not be very useful.

Template:ExampleRobox Let f(x)=x. The exact value of 1.01=f(1.01).

f(x)=12x

The tangent line equation at x=1 is given by

yf(1)=f(1)(x1)y=f(1)(x1)+f(1)
y=12x+12

Let g(x)=y. Suppose g(1.01)f(1.01).

Then, f(1.01)g(1.01)=12(1.01)+12=1.005. Therefore, 1.011.005. Template:Robox/Close

The benefit of linear approximation is that instead of having to use harder to understand functions, we estimate the value of a function using linear functions, arguably the easiest possible calculation we will ever have to use, assuming the value of the derivative is easy to find.

Determining over- or underestimation

Notice that for any approximation we obtain using a tangent line approximation (same as a linear approximation), there exists a remainder term that will make it equal to the true value we can obtain from the function. That is,

Template:Equation

where R2 is the remainder term. This, unfortunately, does not give us a precise estimate of the residual, especially if we cannot find the exact value of the term. While there is a technique to determine the upper bound of a residual for this type of estimate, it will be done much later in Section Template:Calculus/map page.

The best solution we have for now is determining if the estimate we have given is below or above the true value, which can be done with the following technique.

Template:Calculus/Def

Justification: Suppose f(x) is a twice differentiable function in [α,c] and α<c.

Case 1(A): Let f(α)>0 and f(x0)<0 for x0[α,c]. Then, the tangent line, h(x) at (α,f(α)) has positive slope and h(c)>f(c) (see the bottom function of Figure 1).
Case 1(B): Let f(α)>0 and f(x0)>0 for x0[α,c]. Then, the tangent line, h(x) at (α,f(α)) has positive slope and h(c)<f(c).
Case 2(A): Let f(α)<0 and f(x0)<0 for x0[α,c]. Then, the tangent line, h(x) at (α,f(α)) has negative slope and h(c)>f(c).
Case 2(B): Let f(α)<0 and f(x0)>0 for x0[α,c]. Then, the tangent line, h(x) at (α,f(α)) has negative slope and h(c)<f(c) (see the bottom function of Figure 1).

Since a concave down function has h(c)>f(c) no matter the slope of the tangent, and a concave up function has h(c)<f(c) no matter the slope of the tangent, we have justified what we wanted to do.

Template:ExampleRobox Let f(x)=x.

f(x)=12x12=12x
f(x)=12x32

The function is concave down for all x1 because

f(x)=12(x)32=12x3/2.
1212x3/2<0 for all x1.

The last implication is justified because limxf(x)=0 (as an exercise, show this yourself). If f(x) is monotonically decreasing and bounded (which it is – you can show this multiple ways), then we can be certain that the inequality shown is correct.

Because f(x) is certainly concave down from x=1 to x=1.01, 1.011.005 is an overestimate of the true value. Template:Robox/Close

Issues with Linear Approximation

While linear (or tangent line) approximation is a powerful, easy tool that can be used to approximate functions, it does have its issues. These issues were alluded to when introducing the technique. Each issue will highlight why this tool may not be very useful all the time.

Template:ExampleRobox Let f(x)=x3=x1/3. Since we are approximating f(0.01), we may use the tangent line approximation at x=0 to obtain an approximation at f(0.01). Unfortunately, f(0)=limx0x3x does not converge to a finite value. This therefore means that the tangent line is either vertical or does not exist. Since the derivative does not exist at x=0, it is impossible to obtain an accurate approximation using the linear method. Template:Robox/Close

Template:ExampleRobox Let f(x)=x432x2. Since we are approximating f(0.8), and 0.8(1)=0.2 is a small difference in x, we may use the tangent line approximation at x=1 to obtain an approximation at f(0.8).

f(1)=(1)41.5(1)2=11.5=0.5
f(x)=4x33x

The tangent line equation at x=1 is given by

yf(1)=f(1)(x+1)y=f(1)(x+1)+f(1)
y=x1.5

Let g(x)=y. Suppose g(0.8)f(0.8).

Then, f(0.8)g(0.8)=(0.8)1.5=0.7. Therefore, (0.8)41.5(0.8)20.7.

However, this approximation is very off from the actual value. It has an error of R2=0.1496 within the actual value of the function at x=0.8. The reason for this large error has to do with something subtle.

While the derivative does exist at α=1, the function is not monotonic from [1,0.8]: the function will both decrease and increase. Recall from your reading that a function is monotonically decreasing if and only if for any x1,x2[a,b] and x1<x2, h(x1)>h(x2). However, there exists a counterexample for f(x) above, which becomes apparent if you graph the function.

Hence, it would be irresponsible to use a tangent line to approximate the value of (0.8)41.5(0.8)2. Template:Robox/Close

Because this will be something you will learn more comprehensively in Section Template:Calculus/map page, assume that all exercises have a monotonic function. This example is simply meant to illustrate a common pitfall that this method falls to.

Newton-Raphson Method

While tangent line approximations are very helpful, they tend to only be useful when you know a nearby value. However, if there does not exist a nearby value to help estimate its value, then it will be very difficult to obtain a precise estimate of the exact value desired.

The Newton-Raphson method, introduced in Section Template:Calculus/map page, is a useful method to determine the zeros of a function, whether polynomial, transcendental, irrational, exponential, etc. However, the Newton-Raphson method can also be used to approximate values of specific functions.

Template:Calculus/Def

If you read Section Template:Calculus/map page, then this equation should be known and already justified to you.

Template:ExampleRobox Let x=72. We need to manipulate this equation so that we may obtain f(α)=0.

x=72x2=72x272=0

From this, let f(x)=x272. Since x=72 is a root of the equation, we can use the Newton-Rhapson method to approximate 72. First, we choose an initial guess. Since f(8)=8<0<f(9)=9, and f(9)>|f(8)|>0, x0=8 is a good initial guess. Before we can begin, we need the derivative of the function, which can be easily shown to be f(x)=2x. Now we begin by finding the root.

x1=8828=8.5x2=8.58.527228.5=8.47058823529x3=8.470588235298.4705882352927228.47058823529=8.48529411765

Out of convenience, we will stop here. However, the value we have obtained is already correct to four decimal places. Template:Robox/Close

Template:ExampleRobox Let x=2+3. We need to manipulate this equation so that we may obtain f(α)=0. Keep in mind to eliminate as many square roots as possible so that our jobs are easier.

x=2+3x2=2+26+3x25=26x410x2+25=46x410x2+1=0

Notice this equation has four possible roots, but we only care about one of them. Looking back:

1+1=2<2+3<4=2+2

Notice that f(3)=8<0<f(4)=97, so we choose x0=3.

Let f(x)=x410x2+1. Then, f(x)=4x320x.

Notice that 4x(x25)=0x=0x=±5 means that f(x)0 for x(5,4).

Finally, notice that xn+1=xnxn410xn2+14xn320xn cannot be simplified. We are going to have to work with these values. (Keep in mind that even without calculators, many people in the past used slide rulers to work with these ugly values. We have the benefit of an electric computer on our fingertips as opposed to an analog one.)

Now we begin by finding the root.

x1=3848=1963.16666666667x2=19616571296343954=86569275123.14659057866x3=3.146590578660.020117308546661.6861678623.14626445516

Out of convenience, we will stop here. However, the value we have obtained is already correct to six decimal places. Template:Robox/Close

Failure Analysis

Figure 2: The tangent lines of x32x+2 at 0 and 1 intersect the x-axis at 1 and 0 respectively, illustrating why Newton's method oscillates between these values for some starting points.

Of course, as we know from Section Template:Calculus/map page, the Newton-Raphson method is not perfect and will fail in some instances. One obvious instance is when the derivative at a particular point is zero. Because that is in the denominator, we cannot find the next possible root once that occurs. However, there are others.

Starting Point Enters a Cycle

For some functions, some starting points may enter an infinite cycle, preventing convergence. Let

f(x)=x32x+2

and take 0 as the starting point. The first iteration produces 1 and the second iteration returns to 0 so the sequence will alternate between the two without converging to a root (see Figure 2). The real solution of this equation is 1.76929235. In those instances, one should select another starting point.

Derivative does not exist at root

A simple example of a function where Newton's method diverges is trying to find the cube root of zero. The cube root is continuous and infinitely differentiable, except for x=0, where its derivative is undefined:

f(x)=x3.

For any iteration point xn, the next iteration point will be:

xn+1=xnf(xn)f(xn)=xnxn1313xn23=xn3xn=2xn.

The algorithm overshoots the solution and lands on the other side of the y-axis, farther away than it initially was; applying Newton's method actually doubles the distances from the solution at each iteration.

In fact, the iterations diverge to infinity for every f(x)=|x|α, where 0<α<12. In the limiting case of α=12, the iterations will alternate indefinitely between points x0 and x0, so they do not converge in this case either.

Discontinuous Derivative

If the derivative is not continuous at the root, then convergence may fail to occur in any neighborhood of the root. Consider the function

f(x)={0if x=0x+x2sin(2x)if x0
f(x)={0if x=01+2xsin(2x)2cos(2x)if x0

Within any neighborhood of the root, this derivative keeps changing sign as x approaches 0 from the right (or from the left) while f(x)xx2>0 for 0<x<1.

Thus, f(x)f(x) is unbounded near the root, and Newton's method will diverge almost everywhere in any neighborhood of it, even though:

  • the function is differentiable (and thus continuous) everywhere;
  • the derivative at the root is nonzero;
  • f is infinitely differentiable except at the root; and
  • the derivative is bounded in a neighborhood of the root (unlike f(x)/f(x)).

Euler's Method

As will be shown in the examples below, Euler's method does not tend to an approximation as quickly as Newton's method. There are a number of reasons for this, but Euler's method does not stop being useful in spite of this issue. The examples will showcase how useful Euler's method can be however.

Template:ExampleRobox Let y=x. We need to find a differential equation y=f(x,y). Notice that we will do something in the last step which will be important for approximating y(6).

y(x)=xy(x)=12xy=12y(x)

The last step shown here is very important. We need to approximate x. However, if we are trying to approximate x, that cannot be done if we need to use the square root to do so. Instead, since y=x and Euler's method gives us new y-values to work with, we can get an approximation.

We next need to choose an initial point, (x0,y0). This is the only point in which we use the actual value from the function y(x). In this instance, since we want 6, we will choose y(4)=2. From there, we can choose the step size, which can be arbitrary. Here, we will choose Δxstep=1

nxn=xn1+Δxstepyn=yn1+Δxstepf(xn1,yn1)f(xn,yn)142.00000122.00=0.25000252.25000122.25=0.22222362.47222122.47222

As can be seen here, the approximation for 6 is 2.47222. This has an absolute error of 0.0227325, which is pretty good for most contexts. If this was to design a box for example, then this is an okay margin of error. Template:Robox/Close

While the margin of error appears to be big compared to the local linear approximation of 1.01 (with an absolute error of 0.0000124), keep in mind that our step size is considerably larger than the one shown in Example Template:Calculus/map page.1. If we have chosen a smaller step size, then the approximation would be more accurate (if only a little more cumbersome). For instance, with a step size of Δxstep=0.25, the absolute error would be approximately 0.005.

Template:Calculus/Top Nav Template:Calculus/TOC Template:Calculus/Stub Template:BookCat