{ RCSid $Id: root.cal,v 1.4 2019/06/10 13:56:52 greg Exp $ }
{
	root.cal - calculate zeroes of functions using Newton's method.

	2/3/88
}

FTINY : 1e-9;

root(f, x0) = root2(f, x0, x0-f(x0)/lim(f1(f,x0)), nit);

root2(f, x0, x1, i) = if(i,
			if(err-abs(x1-x0),
				x1,
				root2(f,x1,x1-f(x1)/lim(f1(f,x1)),i-1)),
			0);

abs(x) = if(x, x, -x);
lim(x) = if(x, max(x,err), -max(-x,err));

f1(f,x) = (f(x+FTINY)-f(x-FTINY))/(2*FTINY);	{ numerical derivative }

err = 1e-5;
nit = 100;
