Mathematical Principles for Scientific Computing and Visualization  
http://www.farinhansford.com/books/scv
by Gerald Farin and Dianne Hansford

This notebook demonstrates finding roots with piecewise linear interpolation.
Figures 10.1 and 10.3 were generated with this notebook.

Try setting the variable n below to n=4 and n=5. WIth n=5, the roots of the function can be found by intersecting the piecewise linear approximaiton's line segments with the line y=0. But this approach runs into problems with n=4 because the line segments do not intersect the line y=0.


See Chapter 10: Finding Roots for details.

Updated July 2008

(* Specify the output folder *)

SetDirectory[ToFileName[Extract["FileName"/.NotebookInformation[EvaluationNotebook[]],{1},FrontEnd`FileName]]];


(* Define a function *)
f[x_]:=N[(x^2)-0.1];

(* Define the number of piecewise linear points (n+1) to extract from f *)
(* Define the [a,b] the domain over which to evaluate the function *)
(* n=4 used generate FIgure 10.3  *)

(* n=5 used for Figure 10.1 ... and some other combo of a,b and or a modification of f. You can play with it! *)

n=4;
a=-1.2;
b=2;



(* Create a plot of the function and the line y=0 *)
fctplot=Plot[{f[x],0},{x,a,b},PlotStyle->{Thickness[0.01],Thickness[0.001]},Axes->False, PlotRange->All];

(* Generate the n points on the function *)
(* The x-values are uniformly spaced over the domain [a,b] *)
(* And at each x-value, we evaluate f *)
points=Table[{a+((i (b-a))/n),f[a+((i (b-a))/n)]},{i,0,n}];

(* Create a plot the points joined by line segments *)
polyplot=ListPlot[points,Joined->True,Axes->False];

(* Create a plot of points at a particular pointsize *)
pointplot=ListPlot[points,PlotStyle->{PointSize[0.03]},Axes->False];

(* Put all the plots together *)
pic=Show[fctplot,pointplot,polyplot]

(* Output the plot to a postscript file *)
Export["pw_linear_miss.eps",pic];