Nonlinear Equations
by Pavel Ludvk
Introduction
Theorem
Let f be a continuous function on an interval [a, b] and
f (a)f (b) < 0. Then there exists a number c (a, b) that f (c) = 0.
Exercise A
Write an M-File for one step of the Bisection Method. Input:
Function f and limitpoints of an interval [an , bn ]. Output: Limit-
points of an interval [an+1 , bn+1 ].
Exercise B
Create an M-File for the Bisection Method. The program should
stop before doing 24 iterations.
Answer A
p = (a+b)/2;
if f(a)*f(p)<0
b=p;
elseif f(p)*f(b)<0
a=p
else break
end
Numerical Methods Lecture 3 by Pavel Ludvk 8 / 18
Exercises
f (b) f (a)
y = f (a) + (x a).
ba
Mathematical Formula
x0 , x1 = initial guesses,
xn1 xn2
xn = xn1 f (xn1 ) .
f (xn1 ) f (xn2 )
f = ; % the function formula
epsilon = ; % the precision
maxn = ; % limitation on the number of steps
x(1) = ; x(2) = ; % initial approximation
for n = 3 : maxn
x(n) = x(n-1) - f(x(n-1))*(x(n-1)-x(n-2))/(f(x(
n-1))-f(x(n-2)));
if abs(x(n)-x(n-1)) <= epsilon, break, end
disp( x(n-2) x(n-1) x(n) Error)
disp([x(1:n-2) x(2:n-1) x(3:n) (x(3:n)-x(2:n-1))
])
f (a)
x=a+ .
f 0 (a)
Mathematical Formula
x0 = initial guess,
f (xn )
xn+1 = xn .
f 0 (xn )
f 00 (p)
M= .
2f 0 (p)
Local Convergence
A method is locally convergent if there exists an interval
containing a root such that the sequence generated by this
method converge to the root.
Numerical Methods Lecture 3 by Pavel Ludvk 16 / 18
The Newton-Raphson Method Matlab
f = ; % the function formula
%%%%%%%%%%%%%REQUIRES SYMBOLIC TOOLBOX
syms x ; % creating the symbolic variable x
symdf = diff(f(x)); % the derivative function
formula, a symbolic function
df = matlabFunction(symdf); % conversion of a
symbolic function to a normal one
%%%%%%%%%%%%%OTHERWISE COMPUTE DERIVATIVE MANUALLY
epsilon = ; % the precision
maxn = ; % limitation on the number of steps
clear x; x(1) = ; % clearing x as a symbolic
variable; setting initial approximation
for n = 2 : maxn
x(n) = x(n-1) - f(x(n-1))/df(x(n-1));
if abs(x(n)-x(n-1)) <= epsilon, break, end
disp( x(n-1) x(n) Error)
disp([x(1:n-1) x(2:n) (x(1:n)-x(2:n))])