% % Written by: % -- % John L. Weatherwax 2009-04-21 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- close all; clc; clear all; % EPage 136 xs = 20:2:30; ys = xs.^1.4 - sqrt(xs) + 1./xs - 100; % Find an interval that brackets our root graphically plot( xs, ys, '-' ); grid on; % find the value of x such that aitken( xs, ys, x ) ~ 0 use aitken with a bisection like algorithm % xl = 27; fl = aitken( xs, ys, xl ); xr = 28; fr = aitken( xs, ys, xr ); assert( fl*fr < 0 ); while (xr-xl)>1.e-4 xm = 0.5 * ( xl + xr ); fm = aitken( xs, ys, xm ); if fm*fl > 0 fl = fm; xl = xm; else fr = fm; xr = xm; end end 0.5 * ( xl + xr ) % print our root