Task

Pass a function     as an argument     to another function.



Related task

   First-class functions


secant_root(ff,a,b)={
	e = eps() * 2;
	aval=ff(a);
	bval=ff(b);
	while (abs(bval) > e,
		oldb = b;
		b = b - (b - a)/(bval - aval) * bval;
		aval = bval;
		bval = ff(b);
		a = oldb
	);
	b
};
addhelp(secant_root, "secant_root(ff,a,b): Finds a root of ff between a and b using the secant method.");
 
eps()={
	precision(2. >> (32 * ceil(default(realprecision) * 38539962 / 371253907)), 9)
};
addhelp(eps,"Returns machine epsilon for the current precision.");