> f:=x->x^2; > fT1:=D(f)(1)*(x-1)+f(1); > plot({f(x),fT1},x=-1..3);Obviously the two things the function and the tangentline have in common at are their y-value and their slope. Looking at the plot, the line will approximate the function exactly at the base point a and the approximation will be close if you stay close to that base point. To see how far off the approximation becomes on the given interval of the plot it is easy to see that the largest errors occur at the ends of the interval, i.e. and . Simply subtract the y-values to calculate the error.
> abs(f(-1)-subs(x=-1,fT1)); > abs(f(3)-subs(x=3,fT1));Notice that the error grows to four at each end of the interval. How could you find an interval such that the greatest error will be a specific value? Think about this as it will appear in the exercises.
Many problems in mathematics, science, engineering, and business eventually come down to finding the roots of a nonlinear equation. It is a sad fact of life that many mathematical equations cannot be solved analytically. You already know about the formula for solving quadratic polynomial equations. You might not know, however, that there are formulas for solving cubic and quartic polynomial equations. Unfortunately, these formulas are so cumbersome that they are hardly ever used. Even more unfortunately, it has been proven that no formula can exist for finding roots of quintic or higher polynomials. Furthermore, if your equations involve trig functions, then it is even easier to find equations that do not have analytical solutions. For example, the following simple equation cannot be solved to give a formula for x.
> f:=x->sin(x)-x/2; > plot(f(x),x=-6..6);It isn't very hard to write a Maple command that will do one step of Newton's method. The examples below show a very simple method for doing so, using the function defined above and a starting value of . Further iterations can be obtained by using composition, as shown below
> newt:=x->x-f(x)/D(f)(x); > newt(2.2); > newt(newt(2.2)); > (newt@@3)(2.2);However, to simplify things for you, two commands, Newton and NewtonPlot, have been programmed for you. The Newton command takes three arguments: the function, the starting value, and the number of iterations. See the example below for three iterations. Note that these commands are part of the CalcP7 package, so you must load the package first.
> with(CalcP7): > Newton(f(x),x=2.2,3); > NewetonPlot(f(x),x=2.2);One of the problems with Newton's method is knowing when to stop. With a numerical method, you can never get a root exactly, but only a numerical approximation to the root. There are basically two measures of how good your approximation to the root is. One is the absolute value of . If this number is less than a certain tolerance, then you should have a good approximation to the root. The other measure is the change in the value of . If the value of
and are very close, then this can also be a criterion for stopping. You should go back to the example above and experiment with changing the number of iterations.
The worst thing about Newton's method is that it may fail to converge. The key to getting Newton's method to converge is to select a good starting value. The best way to do this is to plot the function and determine approximately where the roots are. Then, use these values to start Newton's method.