You are on page 1of 6

Xavier University – Ateneo de Cagayan

College of Engineering
Electronics Engineering Department

Experiment 3
Methods Based on Linear Interpolation

Submitted by:

MICHAEL BANJO A POBLETE


BS Electronics Engineering – 4

Submitted to:

ENGR RENEL JUANEZA


Instructor
I. Introduction

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.

Ridder’s method is a clever modification of the false position method. It


can be shown to converge quadratically, making it faster than either the
secant or the false position method. It is the method to use if the
derivative of f(x) is impossible or difficult to compute.

II. Theory

Assuming that the root is bracketed in (x1, x2), we first compute f3 = f


(x3), where x3 is the midpoint of the bracket:

Next, we the introduce the function:


g(x) = f(x)e(x−x1)Q

where the constant Q is determined by requiring the points (x1, g1), (x2,
g2), and (x3, g3) to lie on a straight line:

As before, the notation we use is gi = g(xi). The improved value of the


root is then obtained by linear interpolation of g(x) rather than f(x).
III. Data & Results

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).

if nargin < 4; tol = 1.0e6*eps; end


f1 = func(x1);
if f1 == 0; root = x1; return; end
f2 = func(x2);
if f2 == 0; root = x2; return; end
if f1*f2 > 0
error('Root is not bracketed in (a,b)')
end

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

Example 4.4 Codes


Determine the root of f (x) = x3 − 10x2 + 5 = 0 that lies in (0.6, 0.8) with
Ridder’s method.

fex4_4.m: function y = fex4_4(x)


% Function used in Example 4.4

y = (x^3) - (10*x^2) + (5);


end
Example 4.4 Results (Command Window)
>> fplot(@fex4_4,[0.6,0.8])
Warning: Function fails on array inputs. Use element-wise
operators to increase speed.
> In matlab.graphics.function.FunctionLine>getFunction
In matlab.graphics.function.FunctionLine/updateFunction
In matlab.graphics.function.FunctionLine/set.Function_I
In matlab.graphics.function.FunctionLine/set.Function
In matlab.graphics.function.FunctionLine
In fplot>singleFplot (line 223)
In fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line
182)
In fplot>vectorizeFplot (line 182)
In fplot (line 153)
>> grid on

>> grid on
>> ridder(@fex4_4,0.72,0.74)

ans =

0.7346

Example 4.5 Codes


Compute the zero of the function

fex4_5.m: function y = fex4_5(x)


% Function used in Example 4.5

y = 1/((x - 0.3)^2 + 0.01)...


- 1/((x - 0.08)^2 + 0.04);
end
Example 4.5 Results (Command Window)
>> fplot(@fex4_5,[-2,3])
Warning: Function fails on array inputs. Use element-wise
operators to increase speed.
> In matlab.graphics.function.FunctionLine>getFunction
In matlab.graphics.function.FunctionLine/updateFunction
In matlab.graphics.function.FunctionLine/set.Function_I
In matlab.graphics.function.FunctionLine/set.Function
In matlab.graphics.function.FunctionLine
In fplot>singleFplot (line 223)
In fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line
182)
In fplot>vectorizeFplot (line 182)
In fplot (line 153)
>> grid on

>> ridder(@fex4_5,0.1,0.2)

ans =

0.1218
IV. Analysis & Conclusion

The experimenter was tasked to find the roots of given equations


function using linear interpolation methods on MATLAB®. The method
specifically used was Ridder’s method, which is discussed in the
introduction and the theoretical background of this report.

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.

Analysis of the output figure (graph) is essential when using Ridder’s


method. Initially, one must identify at which interval at the x-axis the
root is located prior to using the ridder function. Once such intervals
are identified, the experimenter will then be able to use the ridder
function to find the roots of the given equation. This can be observed in
the data and results as the experimenter finds the roots of the given
examples.

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.

Michael Banjo A Poblete


BSECE - 4