0% found this document useful (0 votes)
3 views18 pages

Week4 Root-Finding Methods

The document discusses root-finding methods in scientific computing, focusing on Bisection, Newton-Raphson, and Secant methods. It compares their convergence rates, requirements, and typical use cases, highlighting the strengths and weaknesses of each approach. Additionally, it includes MATLAB code examples for implementing these methods and a practical exercise to find roots using a specific function.

Uploaded by

timur yasar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views18 pages

Week4 Root-Finding Methods

The document discusses root-finding methods in scientific computing, focusing on Bisection, Newton-Raphson, and Secant methods. It compares their convergence rates, requirements, and typical use cases, highlighting the strengths and weaknesses of each approach. Additionally, it includes MATLAB code examples for implementing these methods and a practical exercise to find roots using a specific function.

Uploaded by

timur yasar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Root-Finding Methods

(Theory & MATLAB)


ECE551 – Scientific Computing with MATLAB
Week 4
Dr. Sinan Genc
Introduction to Root-Finding

A root of a
function f(x) is a
value x = r such
that f(r) = 0.

Examples in Engineering:
•DC operating point in circuits (solve I–V equation).
•Mechanical equilibrium where Ftotal = 0.
•Resonant frequency where Im(Z)=0.
Bracketing vs. Open Root-Finding
Methods
Bracketing Methods Open Methods
Require two points [a,b] such that Start from an initial guess x₀ (or two
f(a)·f(b)<0 x₀,x₁)
Guaranteed convergence (if
Faster but may diverge
continuous)
Example: Bisection Example: Newton–Raphson, Secant
Accuracy, Tolerance, and Order of
Convergence
Convergence criterion: stop when |f(xₙ)| < tolerance (ε).
Order of convergence: how quickly error shrinks:
•Linear → Bisection
•Quadratic → Newton–Raphson
•Superlinear → Secant

if abs(f(x)) < eps


break
end
Bisection Method
Principle and Concept
•Purpose: Find a root of f(x)=0 Given f(x), a, b, tol
•by repeatedly narrowing an interval [a,b]. if f(a)*f(b) >= 0
error('No sign change in [a,b]')
•Key Requirement: end
f(x) must be continuous on [a,b], and while (b - a)/2 > tol
•f(a)⋅f(b)<0 (sign change → at least one root). c = (a + b)/2;
if f(c) == 0, break; end
•Main Step: if f(a)*f(c) < 0
Compute the midpoint b = c;
•c=(a+b)/2 a​ nd evaluate f(c). else
a = c;
•Decision Rule: end
• If f(a)*f(c)<0 → root lies in [a,c] end
• Else → root lies in [c,b] root = (a + b)/2;
•Repeat until the interval width or |f(c)| < tolerance.
Bisection Method
Principle and Concept

Convergence is linear, with error bound:

𝑏−𝑎
|𝐸𝑛 | ≤ 𝑛
2

Guaranteed → the root always remains


inside the interval.

Each iteration halves the error.


Newton–Raphson Method
Concept
Idea:
Replace f(x) locally with its tangent line at xₙ and
use the intersection of that line with the x-axis as
the next guess xₙ₊₁.

Derivation:
Equation of tangent at (xₙ, f(xₙ)) →
y=f(xn)+f′(xn)(x−xn)

Setting y = 0 (x-axis) gives


xn+1 ​= xn ​− f(xn ​)​/ f′(xn ​)

Each step uses the slope (derivative) to jump


closer to the root; the curve is approximated by a
line that “cuts” the axis near the solution.
Newton–Raphson Method
Concept
Quadratic convergence:
Error roughly squares each iteration:
f=@(x)x.^3-x-2;
df=@(x)3*x.^2-1;
|𝐸𝑛+1 | ≈ 𝐶|𝐸𝑛 |2
x=1.5;
The number of correct digits roughly doubles for k=1:10
every iteration. x_new=x-f(x)/df(x);
if abs(f(x_new))<1e-6,
But: May diverge if the initial guess is poor or if break; end
the derivative changes sign. x=x_new;
end

Property Description
Speed Very fast (quadratic)
Requirement Need derivative ( f'(x) )
Risk Diverges if guess too far
Accuracy High near true root
Secant Method
Concept
Purpose: Approximate Newton-Raphson
without computing the derivative.

Idea: Use a finite-difference slope between two recent


points (xₙ, f(xₙ)) and (xₙ₋₁, f(xₙ₋₁)) to estimate f′(xₙ).

Iteration Formula:
xn+1= xn − f(xn)*[(xn − xn-1 ) / (f(xn)−f(xn-1))]

Starting Condition: Requires two initial guesses (x₀,


x₁) close to the root.

Each new step uses a secant line (straight line through


two recent points) instead of a tangent.
Secant Method
Concept
f = @(x) x.^3 - x - 2;
x0 = 1; x1 = 2;
tol = 1e-6;

for k = 1:20
x2 = x1 - f(x1)*(x1 - x0)/(f(x1) - f(x0));
if abs(f(x2)) < tol, break; end
x0 = x1; x1 = x2;
end
root = x2;
Property Description
Derivative required? No
Convergence rate ~1.618 (superlinear)
Initial guesses 2 required
Reliability Faster than Bisection, slightly less stable than Newton
When to use When f′(x) is hard to compute or noisy
Comparing Root-Finding Methods
Speed vs Robustness vs Requirements
Requires Convergence Guarantee of
Method Typical Use Case
Derivative? Rate Convergence
Yes (if sign When robustness
Bisection No Linear
change exists) > speed
When fast
Newton– No (depends precision is
Yes Quadratic
Raphson on initial guess) needed and f′(x)
known
Superlinear Not When f′(x) is
Secant No
(~1.6) guaranteed unknown or noisy
Comparing Root-Finding Methods
Speed vs Robustness vs Requirements
% Define data
methods = {'Bisection','Newton','Secant'};
iters = [25, 5, 8]; % typical iteration counts

% Create figure
figure;
b = bar(iters); % Bar plot
[Link] = 'flat'; % allow individual colors
[Link](1,:) = [0 0.45 0.74]; % blue for Bisection
[Link](2,:) = [0.85 0.33 0.1]; % orange for Newton
[Link](3,:) = [0.47 0.67 0.19]; % green for Secant

% Labeling
set(gca, 'XTickLabel', methods, 'FontSize', 12);
xlabel('Method');
ylabel('Iterations to Converge');
title('Relative Efficiency Comparison');

% Add legend
legend({'Bisection','Newton-Raphson','Secant'}, 'Location', 'northeast');
grid on;
Applications & Exercise
Find root of sin(x)-x/2=0 using all methods
Compare iteration counts
Plot error convergence in MATLAB
Applications & Exercise
Find root of sin(x)-x/2=0 using all methods
Compare iteration counts
Plot error convergence in MATLAB
%% Root Finding Comparison: sin(x) - x/2 = 0
clear; clc; close all;
% Function and derivative
f = @(x) sin(x) - x/2;
df = @(x) cos(x) - 0.5;
tol = 1e-6;
%% --- Bisection Method ---
[root_bis, err_bis] = myBisection(f, 0, 2, tol);
%% --- Newton-Raphson Method ---
[root_new, err_new] = myNewton(f, df, 1, tol);
%% --- Secant Method ---
[root_sec, err_sec] = mySecant(f, 0, 2, tol);
%% --- Display Results ---
fprintf('Bisection Root: %.6f (Iterations = %d)\n', root_bis, length(err_bis));
fprintf('Newton Root: %.6f (Iterations = %d)\n', root_new, length(err_new));
fprintf('Secant Root: %.6f (Iterations = %d)\n', root_sec, length(err_sec));
function [root, err] = myBisection(f, a, b, tol)
if f(a)*f(b) > 0
error('Function has same sign at both endpoints.');
end
err = [];
while (b - a)/2 > tol
c = (a + b)/2;
if f(c) == 0
break;
elseif f(a)*f(c) < 0
b = c;
else
a = c;
end
err(end+1) = abs(f(c));
end
root = (a + b)/2;
end
function [root, err] = myNewton(f, df, x0, tol)
err = [];
for k = 1:50
x1 = x0 - f(x0)/df(x0);
err(end+1) = abs(f(x1));
if abs(f(x1)) < tol
break;
end
x0 = x1;
end
root = x1;
end
function [root, err] = mySecant(f, x0, x1, tol)
err = [];
for k = 1:50
x2 = x1 - f(x1)*(x1 - x0)/(f(x1) - f(x0));
err(end+1) = abs(f(x2)); if abs(f(x2)) < tol
break;
end
x0 = x1;
x1 = x2;
end
root = x2;
end
Comparing Root-Finding Methods
Speed vs Robustness vs Requirements

The Bisection method is your safety net — slow but guaranteed.

Newton–Raphson is the sports car — fast but risky.

Secant method is the practical hybrid between them.

In practice, engineers often start with Bisection for a safe bracket


and then switch to Newton for refinement.

You might also like