Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Introduction To Numerical Analysis For Engineers: - Roots of Non-Linear Equations 2.1-2.4

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Introduction to Numerical Analysis for Engineers

Mathews
• Roots of Non-linear Equations 2.1-2.4
– Heron’s formula
– Stop criteria
– General method 2.1-2.3
• Convergence
• Examples
– Newton-Raphson’s Method 2.4
• Convergence Speed
• Examples
– Secant Method 2.4
• Convergence and efficiency
• Examples
– Multiple roots 2.4
– Bisection 2.2

13.002 Numerical Methods for Engineers Lecture 7


Roots of Nonlinear Equations
a=2;
n=6; heron.m
g=2;
% Number of Digits
dig=5;
Example – Square root sq(1)=g;
for i=2:n
sq(i)= 0.5*radd(sq(i-1),a/sq(i-1),dig);
end
Heron’s Principle ' i
[ [1:n]' sq']
value '

hold off
plot([0 n],[sqrt(a) sqrt(a)],'b')
hold on
plot(sq,'r')
plot(a./sq,'r-.')
plot((sq-sqrt(a))/sqrt(a),'g')
grid on

Guess root
i value

1.0000 2.0000
2.0000 1.5000
Mean is better guess 3.0000 1.4167
4.0000 1.4143
5.0000 1.4143
( )/2 6.0000 1.4143

Iteration Formula
( )/2
13.002 Numerical Methods for Engineers Lecture 7
Roots of Nonlinear Equations
Stop-criteria
Unrealistic stop-criteria

Realistic stop-criteria

Machine
Use combination of the two criteria
Accuracy

f(x) f(x)
‘flat’ f(x) ‘steep’ f(x)

G x x

Cannot require Cannot require


G

13.002 Numerical Methods for Engineers Lecture 7


Roots of Nonlinear Equations
General Method
Example: Cube root
% f(x) = x^3 - a = 0
% g(x) = x + C*(x^3 - a)
a=2;
cube.m
Non-linear Equation n=10;
g=1.0;
C=-0.1;
sq(1)=g;
for i=2:n
Goal: Converging series sq(i)= sq(i-1) + C*(sq(i-1)^3 -a);
end
hold off
plot([0 n],[a^(1./3.) a^(1/3.)],'b')
Rewrite Problem hold on
plot(sq,'r')
plot( (sq-a^(1./3.))/(a^(1./3.)),'g')
grid on
Example

Iteration

13.002 Numerical Methods for Engineers Lecture 7


Roots of Nonlinear Equations
General Method

Convergence

Define k such that if

y
then

Convergence Criteria

Apply successively

x
Convergence

13.002 Numerical Methods for Engineers Lecture 7


Roots of Nonlinear Equations
General Method
y=x
y
Convergence Convergent
y=g(x)

Mean-value Theorem

x1 x0 x
Convergence
y=x >
y y=g(x)
Divergent

x0 x1 x

13.002 Numerical Methods for Engineers Lecture 7


Roots of Nonlinear Equations
General Method
n=10;
g=1.0;
Example: Cube root C=-0.21; cube.m
sq(1)=g;
for i=2:n
sq(i)= sq(i-1) + C*(sq(i-1)^3 -a);
end
Rewrite hold off
f=plot([0 n],[a^(1./3.) a^(1/3.)],'b')
set(f,'LineWidth',2);
hold on
f=plot(sq,'r')
set(f,'LineWidth',2);
f=plot( (sq-a^(1./3.))/(a^(1./3.)),'g')
set(f,'LineWidth',2);
legend('Exact','Iteration','Error');
Convergence f=title(['a = ' num2str(a) ', C = ' num2str(C)])
set(f,'FontSize',16);
grid on

Converges more rapidly for small

13.002 Numerical Methods for Engineers Lecture 7


Roots of Nonlinear Equations
General Method
Converging, but how close?

Absolute error

General Convergence Rule

13.002 Numerical Methods for Engineers Lecture 7


Roots of Nonlinear Equations
Newton-Raphson Method
Non-linear Equation

Convergence Criteria
f(x)
Fast Convergence

Newton-Raphson Iteration

13.002 Numerical Methods for Engineers Lecture 7


Roots of Nonlinear Equations
Newton-Raphson Method
a=26;
n=10; sqr.m
g=1;
Example – Square Root sq(1)=g;
for i=2:n
sq(i)= 0.5*(sq(i-1) + a/sq(i-1));
end
hold off
plot([0 n],[sqrt(a) sqrt(a)],'b')
Newton-Raphson hold on
plot(sq,'r')
plot(a./sq,'r-.')
plot((sq-sqrt(a))/sqrt(a),'g')
grid on

Same as Heron’s formula

13.002 Numerical Methods for Engineers Lecture 7


Roots of Nonlinear Equations
Newton-Raphson Method

a=10;
n=10;
g=0.19; div.m
sq(1)=g;
for i=2:n
sq(i)=sq(i-1) - sq(i-1)*(a*sq(i-1) -1) ;
end
hold off
plot([0 n],[1/a 1/a],'b')
hold on
plot(sq,'r')
plot((sq-1/a)*a,'g')
grid on
legend('Exact','Iteration','Error');
title(['x = 1/' num2str(a)])
Approximate Guess

Newton-Raphson

13.002 Numerical Methods for Engineers Lecture 7


Roots of Nonlinear Equations
Newton-Raphson Method
Convergence Speed

Taylor Expansion

Second Order Expansion

Relative Error

Quadratic Convergence

General Convergence Rate


Convergence Exponent

13.002 Numerical Methods for Engineers Lecture 7


Roots of Nonlinear Equations
Secant Method
1. In Newton-Raphson we have to evaluate 2 functions

2. may not be given in closed, analytical form, i.e. it may be a


result of a numerical algorithm

f(x)
Approximate Derivative

Secant Method Iteration

Only 1 function call per iteration:

13.002 Numerical Methods for Engineers Lecture 7


Roots of Nonlinear Equations
Secant Method
Convergence Speed

Absolute Error

Error Exponent

Taylor Series – 2nd order

Relative Error

Error improvement for each function call


Secant Method
Newton-Raphson

Exponents called Efficiency Index

13.002 Numerical Methods for Engineers Lecture 7


Roots of Nonlinear Equations
Multiple Roots
p-order Root

Newton-Raphson

=>

f(x)
Convergence

Slower convergence the higher the order of the root

13.002 Numerical Methods for Engineers Lecture 7


Roots of Nonlinear Equations
Bisection

Algorithm

f(x)

n = n+1

yes

no Less efficient than Newton-Raphson and


Secant methods, but often used to isolate
interval with root and obtain approximate
value. Then followed by N-R or Secant
method for accurate root.
13.002 Numerical Methods for Engineers Lecture 7
Roots of Nonlinear Equations
Bisection
% Root finding by bi-section
Algorithm f=inline(' a*x -1','x','a'); bisect.m
a=2
figure(1); clf; hold on
x=[0 1.5]; eps=1e-3;
err=max(abs(x(1)-x(2)),abs(f(x(1),a)-f(x(2),a)));
while (err>eps & f(x(1),a)*f(x(2),a) <= 0)
xo=x; x=[xo(1) 0.5*(xo(1)+xo(2))];
if ( f(x(1),a)*f(x(2),a) > 0 )
n = n+1 x=[0.5*(xo(1)+xo(2)) xo(2)]
end
x
err=max(abs(x(1)-x(2)),abs(f(x(1),a)-f(x(2),a)));
b=plot(x,f(x,a),'.b'); set(b,'MarkerSize',20);
grid on;
end

yes

no

13.002 Numerical Methods for Engineers Lecture 7

You might also like