next up previous
Next: Exercises Up: No Title Previous: Combining plots

More on fsolve

As you have seen before, it is not always possible to express the answer to a given problem exactly. It can also happen that there is an exact answer, but the expression is prohibitively complicated. In these situations, some method of approximating solutions is necessary.

For the task of finding the roots of a function, the Maple command fsolve tries to find approximations to the roots. In some situations, the output of an fsolve command is the final answer to a problem. More frequently, however, you'd have to use fsolve to get an intermediate value; and then use the result of fsolve in later steps of the computation.

For example, suppose we want to find the tangent line to $y = \cos x - x$at the point where the graph crosses the x-axis, and the y-intercept of this tangent line. Then first we must find the x-intercept; then we have to use the result of the computation to get the equation of the tangent line.

   > f := x -> cos(x) - x;
   > soln := fsolve(f(x)=0,x);
The tangent line is then given by
   > tanline := x -> D(f)(soln)*(x-soln);
(Why?)

Therefore the y-intercept is the value of y at x=0:

   > tanline(0);

In some situations, the equation you give to fsolve may have more than one root. If fsolve returns more than one solution, you can select the particular solution you want to work with, by means of a number enclosed in square brackets: e. g. [2]. For example, suppose we repeat the above exercise using the equation y = x3 - 4x2 + 4x - 1, and we want to find the tangent line at each root. One approach is the following.

   > f := x -> x^3 - 4*x^2 + 4*x - 0.9;
   > solns := fsolve(f(x)=0,x);
   > tanline1 := x -> D(f)(solns[1])*(x-solns[1]);
   > tanline2 := x -> D(f)(solns[2])*(x-solns[2]);
   > tanline3 := x -> D(f)(solns[3])*(x-solns[3]);


next up previous
Next: Exercises Up: No Title Previous: Combining plots

Christine M Palmer
9/29/1998