Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
54 views

Lecture Module 2 - Nonlinear Equations

This document provides an overview of different numerical methods for finding the roots or zeros of nonlinear equations, including the bisection method, Newton-Raphson method, and secant method. It begins with an introduction to nonlinear functions and the need to find numerical solutions for nonlinear equations. It then covers each method in detail, providing the theoretical background and algorithm for each approach. Examples are included to demonstrate how to apply each technique to solve nonlinear equations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Lecture Module 2 - Nonlinear Equations

This document provides an overview of different numerical methods for finding the roots or zeros of nonlinear equations, including the bisection method, Newton-Raphson method, and secant method. It begins with an introduction to nonlinear functions and the need to find numerical solutions for nonlinear equations. It then covers each method in detail, providing the theoretical background and algorithm for each approach. Examples are included to demonstrate how to apply each technique to solve nonlinear equations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

ENGINEERING MATHEMATICS 4

(BWM 30603)
Lecture Module 2: Nonlinear Equations

Waluyo Adi Siswanto


Universiti Tun Hussein Onn Malaysia

This module is licensed under a Creative Commons Attribution 3.0 License.

Topics

Understanding nonlinear functions

Intermediate value theorem

Finding the roots of nonlinear equations

Bisection method

Newton-Raphson method

Secant method

Lecture Module 2

BWM 30603

Understanding nonlinear function


Linear function is a straight line

Linear equations:

Then you can


find the solution
easily !
Lecture Module 2

BWM 30603

Understanding nonlinear function


Nonlinear function is NOT a straight line

Lecture Module 2

BWM 30603

Understanding nonlinear function

nonlinear equations

Some expressions of nonlinear equations:

In engineering (for example in Control) solving the roots is called solving Zeros
Therefore, the variables resulting zero values of the function must be found.

x=?
x=?

Lecture Module 2

BWM 30603

How to find the roots (Zeros) ?

Basic Idea - Graphical Approach

Plotting the the nonlinear function, then you will see the zeros

By inputting the value


around the zero location
you can find the roots

Lecture Module 2

BWM 30603

How to find the roots (Zeros) ?

Basic Idea Intermediate Value

How to predict ????


If you try x=a=0.3

0.3

(negative)

If you try x = 1
(positive)

Conclusion : The roots (zeros) occurs between negative and positive results
or y3(0,3) multiply by y3(1) is negative
Mathematical expression:
If
Lecture Module 2

f (a) f (b)<0 the root will be in a range of interval [a ,b]


BWM 30603

Example 2-1
Given a function

y ( x)=sin (2x)+x 33

Plot the function and predict the root using the idea of Intermediate Value Theorem

First trial
Second trial (in between 1 and 2)

Third trial (between 1.2 and 1.5)

It is then predicted, the root x = 1.37


Lecture Module 2

BWM 30603

How to find the roots (Zeros) ?

Bisection Method

In Bisection Method,
Method it used the idea of Intermediate Value Theorem and introduces the
predicted root by dividing the interval [a ,b] into two sections equally c=(a+b)/2
The routine algorithm can be systematically structured below:

1. Define

c=(a+b)/2

root=c and exit

2. If

(bc) then accept

3. If

f (c) f (b)<0 then a=c otherwise b=c

4. Return to Step 1

Lecture Module 2

BWM 30603

The criterion can be


also set as

(ba)

How to find the roots (Zeros) ?

Bisection Method

The algorithm can be easier understood by diagram

b
c=(a+b)/2

f (c) f (b)<0 ? YES


a=c

b
b
c=(a+b)/2

Lecture Module 2

BWM 30603

10

How to find the roots (Zeros) ?

Bisection Method

The algorithm can be easier understood by diagram

b
c=(a+b)/2

f (c) f (b)<0 ? NO
b=c

a
a
c=(a+b)/2

Lecture Module 2

BWM 30603

11

Bisection Method

m function

k = 1;
x(k) = (a + b) / 2;
while ((k <= N) && ((b - a) / 2) >= Tol)
if f(x(k)) == 0
error([ 'bisection: condition f(' num2str(x(k)) ...
')~=0 didn''t apply' ]);
end
if (f(x(k)) * f(a)) < 0
b = x(k);
else
a = x(k);
end
k = k + 1;
x(k) = (a + b) / 2;
c=x(k);
end

function [k,c] = bisection(f, a, b, Tol)


%
% bisection(f, a, b, Tol)
%
% Input:
% f - function given as a string
% a - lower bound
% b - upper bound
%
% Output:
% k - number of iterations performed
% c - root of the function
%
% Example:
% [k,c] = bisection( 'x^6-x-1', 1, 2, 0.00001 )
format long;
N= 1e4;
if nargin == 3
Tol = 1e-4;
end
f = inline(f);
if (f(a) * f(b) > 0) || (a >= b)
error('INCORRECT INPUT f(a)*f(b)>0 or a>=b');
end

Lecture Module 2

BWM 30603

12

Example 2-2
Given a system a response following a function

y ( x)= x x1

a) Find a system at a stable condition (zero) in range [1,2] using bisection method.
Stop your prediction when the error (convergence criteria) less then 0.0005

b) Verify your calculation by plotting the function, and show your predicted result is correct
c) Verify the result by using freemat.

Lecture Module 2

BWM 30603

13

No
0

a
1

b
2

f(a)
-1

1.5
1

1.5

-1

1.25

1.125

-0.09771

1.1875

1.125

0.020619

1.134766 -0.01958

1.133789

0.003906

0.000427

0.001953
0.000427

-0.0096
1.134766

-0.0096

1.134277

Lecture Module 2

0.061578

1.136719 -0.01958

1.132813

0.007813

0.020619

1.133789
10

0.061578

1.140625 -0.01958

1.132813

0.015625

-0.01958

1.134766
9

0.233269

1.140625 -0.09771

1.132813

0.03125

0.061578

1.136719
8

0.616653

-0.09771

1.132813
7

0.0625

0.233269
1.15625

1.125

1.564697

-0.09771

1.140625
6

0.125

0.616653

1.15625
5

1.564697
-0.09771

1.25

1.125

0.5
8.890625

-1

1.1875
4

error

1.564697

1.125
3

f(b)
61

8.890625

1.25
2

f( c)

0.000427
-0.00459

BWM 30603

0.000977
0.000488

14

Lecture Module 2

BWM 30603

15

Lecture Module 2

BWM 30603

16

How to find the roots (Zeros) ?

Newton-Raphson Method

The strategy behind the Newton-Raphson method is to approximate the curve of y ( x)


by its tangential line. This tangential line (or slope) is the first derivative y ' ( x)

y ( x o)
= y ' ( x o)
x1 xo

y ( x)

root

xo

x1

y ( x o )= y ' ( x o )( x 1 x o )
y ( x o )= y ' ( x o ) x 1 y ' ( x o ) x o

y ' ( x o)

y ' ( x o ) x 1= y ' ( x o ) x o y ( x o )
y ( x o)
x 1 = x o
y ' ( x o)

y ( xo )

Lecture Module 2

BWM 30603

17

How to find the roots (Zeros) ?

Newton-Raphson Method

x 1 = x o

y ( xo)
y ' ( x o)

is then expressed in general rule

y ( xi )
x i+1 = x i
y ' ( xi )

x i : initial value of root prediction

x i+1 : the next predicted value of the root


Convergence criterion =x i+1 x i

Lecture Module 2

BWM 30603

18

How to find the roots (Zeros) ?

Newton-Raphson Method

The Newton-Raphson algorithm can be concluded below:

1. Identify y ( x) and y ' ( x)


2. Set initial predicted root x i
3. Calculate the new root based on the initial value ( x i )

y ( xi )
x i+1 = x i
y ' ( xi )
4. Check the convergence criterion
5. Use x i+1

x i+1 x i , exit

as a new initial value

6. Return to Step 3
Lecture Module 2

BWM 30603

19

Newton-Raphson Method

m function

function [numIter,root] = newtonraphson(func,dfunc,x,tol)


% Newton--Raphson method
% example:
%
[n,res] = newtonraphson('x^6-x-1','6*x^5-1',1.0)
format long;
func = inline(func);
dfunc = inline(dfunc);
if nargin == 3
tol = 1.0e6*eps;
end
for i = 1:1000
dx = -(func(x)/dfunc(x));
x = x + dx;
if abs(dx) < tol
root = x;
numIter = i;
return
end
end
fprintf('more then 1000 trial, too small tolerance /n')

Lecture Module 2

BWM 30603

20

Example 2-3
Given a system a response following a function

y ( x)= x x1

a) Find a system at a stable condition (zero) by using Newton-Raphson method.


The initial value is 1.
Stop your prediction when the error (convergence criterion) less then 0.00001

b) Verify your calculation by plotting the function, and show your predicted result is correct

c) Plot the convergence control to see the result converge to a solution


d) Verify your calculation by using Newton-Raphson m function in freemat
Lecture Module 2

BWM 30603

21

y ( x)= x x1
5

y ' ( x)=6x 1
Iteration

y(x)

y'(x)

(x^6 - x -1) (6x^5 -1)

Lecture Module 2

1.2

-1

0.785984 13.92992

0.2

1.143575843 0.093032 10.73481 0.056424

1.134909462 0.0019074 10.29685 0.008666

1.134724221 8.537E-07 10.28763 0.000185

1.134724138 1.703E-13 10.28763

BWM 30603

8.3E-08

22

Lecture Module 2

BWM 30603

23

Lecture Module 2

BWM 30603

24

How to find the roots (Zeros) ?

Secant Method

In Newton-Raphson requires the first derivative of the function.


There are certain functions whose derivatives my be difficult or inconvenient to evaluate.
In Secant Method, the derivative is replaced by a difference approximation
based on successive estimates

y ' ( x i+1 )

y( x i ) y( x i+1 )
x i xi+1

y ( x i+1 )
x i+2 = xi+1
y ' ( xi+1 )

then substitute in Newton-Raphson iteration formula

y( xi+1 ) ( x i x i+1 )
x i+2 = xi+1
y( x i ) y( x i+1 )
x i y( x i+1 ) x i+1 y( x i )
x i+2 =
y ( x i+1 ) y( x i )

Lecture Module 2

BWM 30603

i=0,1,2,n

25

How to find the roots (Zeros) ?

Secant Method

x i y( x i+1 ) x i+1 y( x i )
x i+2 =
y ( x i+1 ) y( x i )

i=0,1,2,n

To implement the iteration, it requires two points that satisfy the intermediate
value theorem. One has positive value and the other one must be negative.

y ( x)
x 0 y( x1 ) x 1 y( x 0 )
x2=
y ( x 1 ) y ( x 0 )

root

Table data

xo

Iteration
(i)

xi

y ( xi)

x0

y ( x0 )

x1

y ( x 1)

x2

Lecture Module 2

y ( x 1)
x2

x1

y ( xo )
BWM 30603

26

How to find the roots (Zeros) ?

Secant Method

See the 3-step

DANCING calculation pattern in every iteration

Table data
Iteration
(i)

xi

y ( xi)

x0

y ( x0 )

x1

y ( x 1)

x2

STEP 1

x2=

Lecture Module 2

BWM 30603

x 0 y( x1 ) x 1 y( x 0 )
y ( x 1 ) y ( x 0 )

27

How to find the roots (Zeros) ?

Secant Method

See the 3-step

DANCING calculation pattern in every iteration

Table data
Iteration
(i)

xi

x0

y ( x0 )

x1

y ( x 1)

x2

y ( xi)

STEP 2

x2=

Lecture Module 2

BWM 30603

x 0 y( x1 ) x 1 y( x 0 )
y ( x 1 ) y ( x 0 )

28

How to find the roots (Zeros) ?

Secant Method

See the 3-step

DANCING calculation pattern in every iteration

Table data
Iteration
(i)

xi

y ( xi)

x0

y ( x0 )

x1

y ( x 1)

x2

STEP 3

x2=

Lecture Module 2

BWM 30603

x 0 y( x1 ) x 1 y( x 0 )
y ( x 1 ) y ( x 0 )

29

How to find the roots (Zeros) ?

Secant Method

The Secant Method algorithm can be concluded below:

1. Select initial points

x1

x 0 and

also calculate y ( x 0 ) and y ( x 1 )

2. Check the requirement

y ( x 0 ) y ( x 1 )<0 , continue

3. Do the calculation of

x 0 y( x1 ) x 1 y( x 0 )
x2=
y ( x 1 ) y ( x 0 )

4. Check the convergence criterion

x i+1 x i , exit

5. Move one increment and return to Step 3

Lecture Module 2

BWM 30603

30

Secant Method

m function

function [numIter,new] = secant ( f, x0, x1, TOL)


% Secant method
% Example:
%
[n,result] = secant ( 'x^6-x-1', 1, 2, 0.0001 )
format long;
f=inline(f);
older = x0; old = x1;
folder = f(older);
Nmax=1000;
for i = 2 : Nmax
fold = f(old);
dx = fold * ( old - older ) / ( fold - folder );
new = old - dx;
numIter=i;
if ( abs(dx) < TOL )
return
else
older = old;
old = new;
folder = fold;
end
numIter=i;
end
disp('ERROR: Maximum number of 1000 iterations exceeded,')
disp('
too small tolerance !')

Lecture Module 2

BWM 30603

31

Example 2-4
Given a system a response following a function

y ( x)= x x1

a) Find a system at a stable condition (zero) by using Secant method.


Use the initial values at 1 and 2
Stop your prediction when the error (convergence criterion) less then 0.00001

b) Verify your calculation by plotting the function, and show your predicted result is correct

c) Plot the convergence control to see the result converge to a solution


d) Verify your calculation by using secant m function in freemat
Lecture Module 2

BWM 30603

32

Iteration

y(x)

(x^6 - x -1)

Lecture Module 2

-1

61

1.016129032 -0.915368 0.983871

1.030674754 -0.831921 0.014546

1.175688944 0.4652272 0.145014

1.123679065 -0.110633

6
7
8

1.133671081 -0.010806 0.009992


1.134752682 0.0002937 0.001082
1.134724066 -7.48E-07 2.86E-05
BWM 30603

0.05201

33

Lecture Module 2

BWM 30603

34

Lecture Module 2

BWM 30603

35

How to find zeros in SMath ?

Lecture Module 2

BWM 30603

36

Lecture Module 2

BWM 30603

37

You might also like