Professional Documents
Culture Documents
College of Engineering
Electronics Engineering Department
Experiment 3
Methods Based on Linear Interpolation
Submitted by:
Submitted to:
The secant and the false position methods are closely related. Both
methods require two starting estimates of the root, say, x1 and x2. The
function f(x) is assumed to be approximately linear near the root, so
that the improved value x3 of the root can be estimated by linear
interpolation between x1 and x2.
II. Theory
where the constant Q is determined by requiring the points (x1, g1), (x2,
g2), and (x3, g3) to lie on a straight line:
ridder
function root = ridder(func,x1,x2,tol)
% Ridder's method for computing the rooth of f(x) = 0
% USAGE: root = ridder(func,a,b,tol)
% INPUT:
% func = handle of function that returns f(x).
% x1,x2 = limits of the interval containing the root.
% tol = error tolerance (default is 1.0e6*eps).
% OUTPUT:
% root = zero of f(x) (root = NaN if failed to converge).
for i = 0:30
% Compute improved root from Riddler's formula
x3 = 0.5*(x1 + x2); f3 = func(x3);
if f3 == 0; root = x3; return; end
s = sqrt(f3*2 - f1*f2);
if s == 0; root = NaN; return; end
x4 = x3 + dx; f4 = func(x4);
% Test for convergence
if i > 0;
if abs(x4 - xOld) < tol*max(abs(x4),1,0)
root = x4; return;
end
end
end
xOld = x4;
% Re-bracket the root
if f3*f4 > 0
if f1*f4 < 0; x2 = x4; f2 = f4;
else x1 = x4; f1 = f4;
end
else
x1 = x3; x2 = x4; f1 = f3; f2 = f4;
end
root = NaN;
end
>> grid on
>> ridder(@fex4_4,0.72,0.74)
ans =
0.7346
>> ridder(@fex4_5,0.1,0.2)
ans =
0.1218
IV. Analysis & Conclusion
The ridder function, which implements Ridder’s method, does not exist
in the MATLAB® software by default. Therefore, prior to finding the
roots of the given equations, the experimenter created a file for the
ridder function which will be used further into the experiment.
The experiment also gives a glimpse of how one can easily find the
roots of non-linear equations without the need for manual calculations
by using simulation software such as MATLAB® to generate the output
graphs and results.