0% found this document useful (0 votes)
39 views46 pages

Lecture Module 2 Presentation

The document is a lecture module on solving nonlinear equations. It discusses understanding nonlinear functions and methods for finding roots, including the bisection method, Newton-Raphson method, and secant method. It provides examples of applying the bisection method to find roots of nonlinear equations and functions.
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)
39 views46 pages

Lecture Module 2 Presentation

The document is a lecture module on solving nonlinear equations. It discusses understanding nonlinear functions and methods for finding roots, including the bisection method, Newton-Raphson method, and secant method. It provides examples of applying the bisection method to find roots of nonlinear equations and functions.
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
You are on page 1/ 46

BDA34003

ENGINEERING MATHEMATICS 4

Lecture Module 2: Nonlinear Equations

Waluyo Adi Siswanto


[email protected]
Learning Outcomes

➢ Students know some common methods to find roots of


nonlinear equations or polynomial functions
➢ Students will be able to implement the methods to solve
engineering problems
➢ Students will be able to use mathematical tools to find
roots of nonlinear equations or polynomial functions

BDA34003 Engineering Mathematics 4 2


Waluyo Adi Siswanto ([email protected])
Topics

➢ Understanding nonlinear functions


➢ Intermediate value theorem
➢ Finding the roots of nonlinear equations
➢ Bisection method
➢ Newton-Raphson method
➢ Secant method

BDA34003 Engineering Mathematics 4 3


Waluyo Adi Siswanto ([email protected])
Understanding
nonlinear function
Linear function is a straight line

Linear equations:

Then you can


find the solution
easily !

BDA34003 Engineering Mathematics 4 4


Waluyo Adi Siswanto ([email protected])
Understanding
nonlinear function
Nonlinear function is NOT a straight line

BDA34003 Engineering Mathematics 4 5


Waluyo Adi Siswanto ([email protected])
Understanding
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=?

BDA34003 Engineering Mathematics 4 6


Waluyo Adi Siswanto ([email protected])
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

BDA34003 Engineering Mathematics 4 7


Waluyo Adi Siswanto ([email protected])
How to find the roots (Zeros) ?
Basic Idea – Intermediate Value

How to predict ????

If you try x=a=0.3

0.3
(negative)
1
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 f (a) f (b)< 0 the root will be in a range of interval [a ,b]

BDA34003 Engineering Mathematics 4 8


Waluyo Adi Siswanto ([email protected])
Example 2-1

Given a function y ( x)=sin (2x)+ x 3−3


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

BDA34003 Engineering Mathematics 4 9


Waluyo Adi Siswanto ([email protected])
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

2. If (b−c)⩽ϵ then accept root=c and exit The criterion can be


also set as
3. If f (c) f (b)< 0 then a=c otherwise b=c
(b−a)
⩽ϵ
4. Return to Step 1 2

BDA34003 Engineering Mathematics 4 10


Waluyo Adi Siswanto ([email protected])
How to find the roots (Zeros) ?
Bisection Method

The algorithm can be easier understood by diagram

a b

c=(a+ b)/2

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


a=c b

c=(a+ b)/2

BDA34003 Engineering Mathematics 4 11


Waluyo Adi Siswanto ([email protected])
How to find the roots (Zeros) ?
Bisection Method

The algorithm can be easier understood by diagram

a b

c=(a+ b)/2

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

c=(a+ b)/2

BDA34003 Engineering Mathematics 4 12


Waluyo Adi Siswanto ([email protected])
Bisection Method
m function

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


% x(k) = (a + b) / 2;
% bisection(f, a, b, Tol) while ((k <= N) && ((b - a) / 2) >= Tol)
% if f(x(k)) == 0
% Input: error([ 'bisection: condition f(' num2str(x(k)) ...
% f - function given as a string ')~=0 didn''t apply' ]);
% a - lower bound end
% b - upper bound if (f(x(k)) * f(a)) < 0
% b = x(k);
% Output: else
% k - number of iterations performed a = x(k);
% c - root of the function end
% k = k + 1;
% Example: x(k) = (a + b) / 2;
% [k,c] = bisection( 'x^6-x-1', 1, 2, 0.00001 ) c=x(k);
end
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

BDA34003 Engineering Mathematics 4 13


Waluyo Adi Siswanto ([email protected])
Example 2-2

6
Given a system a response following a function y ( x)= x − x−1

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.

BDA34003 Engineering Mathematics 4 14


Waluyo Adi Siswanto ([email protected])
No a c b f(a) f( c) f(b) error
0 1 2 -1 61
1.5 8.890625 0.5
1 1 1.5 -1 8.890625
1.25 1.564697
2 1 1.25 -1 1.564697
1.125 -0.09771 0.125
3 1.125 1.25 -0.09771 1.564697
1.1875 0.616653 0.0625
4 1.125 1.1875 -0.09771 0.616653
1.15625 0.233269 0.03125
5 1.125 1.15625 -0.09771 0.233269
1.140625 0.061578 0.015625
6 1.125 1.140625 -0.09771 0.061578
1.132813 -0.01958 0.007813
7 1.132813 1.140625 -0.01958 0.061578
1.136719 0.020619 0.003906
8 1.132813 1.136719 -0.01958 0.020619
1.134766 0.000427 0.001953
9 1.132813 1.134766 -0.01958 0.000427
1.133789 -0.0096 0.000977
10 1.133789 1.134766 -0.0096 0.000427
1.134277 -0.00459 0.000488

BDA34003 Engineering Mathematics 4 15


Waluyo Adi Siswanto ([email protected])
BDA34003 Engineering Mathematics 4 16
Waluyo Adi Siswanto ([email protected])
A. Locate where the folder where you
collect m functions

B. Add

C. Save then Done

D. Restart FreeMat

BDA34003 Engineering Mathematics 4 17


Waluyo Adi Siswanto ([email protected])
BDA34003 Engineering Mathematics 4 18
Waluyo Adi Siswanto ([email protected])
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) − y ( x o)
root = y ' ( x o)
x1− xo

− y ( x o )= y ' ( x o )( x 1 − x o )
xo x1 x
− 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 ( xo)
y ( xo ) x 1 = x o−
y ' ( x o)

BDA34003 Engineering Mathematics 4 19


Waluyo Adi Siswanto ([email protected])
How to find the roots (Zeros) ?
Newton-Raphson Method

y ( xo)
x 1 = x o− is then expressed in general rule
y ' ( x o)

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∣

BDA34003 Engineering Mathematics 4 20


Waluyo Adi Siswanto ([email protected])
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 ∣x i+ 1 − x i∣⩽ϵ , exit

5. Use x i+ 1 as a new initial value

6. Return to Step 3

BDA34003 Engineering Mathematics 4 21


Waluyo Adi Siswanto ([email protected])
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')

BDA34003 Engineering Mathematics 4 22


Waluyo Adi Siswanto ([email protected])
Example 2-3

6
Given a system a response following a function y ( x)= x − x−1

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

BDA34003 Engineering Mathematics 4 23


Waluyo Adi Siswanto ([email protected])
6
y ( x)= x − x−1
5
y ' ( x)=6x −1

Iteration x y(x) y'(x) ε


(x^6 - x -1) (6x^5 -1)
1 1 -1 5
2 1.2 0.785984 13.92992 0.2
3 1.143575843 0.093032 10.73481 0.056424
4 1.134909462 0.0019074 10.29685 0.008666
5 1.134724221 8.537E-07 10.28763 0.000185
6 1.134724138 1.703E-13 10.28763 8.3E-08

BDA34003 Engineering Mathematics 4 24


Waluyo Adi Siswanto ([email protected])
BDA34003 Engineering Mathematics 4 25
Waluyo Adi Siswanto ([email protected])
BDA34003 Engineering Mathematics 4 26
Waluyo Adi Siswanto ([email protected])
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 )− y( x i+ 1 )
y ' ( x i+ 1 )≈ then substitute in Newton-Raphson iteration formula
x i − xi + 1

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

x i y( x i+ 1 )− x i+ 1 y( x i )
x i+ 2 = i=0,1,2,⋯n
y ( x i+ 1 )− y( x i )

BDA34003 Engineering Mathematics 4 27


Waluyo Adi Siswanto ([email protected])
How to find the roots (Zeros) ?
Secant Method

x i y( x i+ 1 )− x i+ 1 y( x i )
x i+ 2 = i=0,1,2,⋯n
y ( x i+ 1 )− y( x i )

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= root
y ( x 1 )− y ( x 0 ) y ( x1)

Table data
xo x2
Iteration x
(i)
xi y ( xi) x1
0 x0 y ( x0 )
1 x1 y ( x 1)
2 x2 y ( xo )
BDA34003 Engineering Mathematics 4 28
Waluyo Adi Siswanto ([email protected])
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)

0 x0 y ( x0 )
1 x1 y ( x 1)
STEP 1
2 x2
x 0 y( x1 )− x 1 y( x 0 )
x2=
y ( x 1 )− y ( x 0 )

BDA34003 Engineering Mathematics 4 29


Waluyo Adi Siswanto ([email protected])
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)
STEP 2
0 x0 y ( x0 )
1 x1 y ( x 1)
2 x2
x 0 y( x1 )− x 1 y( x 0 )
x2=
y ( x 1 )− y ( x 0 )

BDA34003 Engineering Mathematics 4 30


Waluyo Adi Siswanto ([email protected])
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)

0 x0 y ( x0 )
STEP 3
1 x1 y ( x 1)
2 x2
x 0 y( x1 )− x 1 y( x 0 )
x2=
y ( x 1 )− y ( x 0 )

BDA34003 Engineering Mathematics 4 31


Waluyo Adi Siswanto ([email protected])
How to find the roots (Zeros) ?
Secant Method

The Secant Method algorithm can be concluded below:

1. Select initial points x 0 and x1 also calculate y ( x 0 ) and y ( x 1 )

2. Check the requirement y ( x 0 ) y ( x 1 )< 0 , continue

x 0 y( x1 )− x 1 y( x 0 )
3. Do the calculation of 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

BDA34003 Engineering Mathematics 4 32


Waluyo Adi Siswanto ([email protected])
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 ofEngineering


BDA34003 1000 iterations exceeded,')
Mathematics 4 33
disp(' too small tolerance
Waluyo!')Adi Siswanto ([email protected])
Example 2-4

6
Given a system a response following a function y ( x)= x − x−1

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

BDA34003 Engineering Mathematics 4 34


Waluyo Adi Siswanto ([email protected])
Iteration x y(x) ε
(x^6 - x -1)
0 1 -1
1 2 61
2 1.016129032 -0.915368 0.983871
3 1.030674754 -0.831921 0.014546
4 1.175688944 0.4652272 0.145014
5 1.123679065 -0.110633 0.05201
6 1.133671081 -0.010806 0.009992
7 1.134752682 0.0002937 0.001082
8 1.134724066 -7.48E-07 2.86E-05

BDA34003 Engineering Mathematics 4 35


Waluyo Adi Siswanto ([email protected])
BDA34003 Engineering Mathematics 4 36
Waluyo Adi Siswanto ([email protected])
BDA34003 Engineering Mathematics 4 37
Waluyo Adi Siswanto ([email protected])
How to find zeros in SMath ?

BDA34003 Engineering Mathematics 4 38


Waluyo Adi Siswanto ([email protected])
Example 2-5

6 3
Two nonlinear functions y ( x)= x − x−1 g ( x)=−x +5

Find the positive intersection (in x range between 0 and 1.5)


- Use secant formula! , using the tolerance 0.0001
- verify using freemat
- verify using SMath

BDA34003 Engineering Mathematics 4 39


Waluyo Adi Siswanto ([email protected])
The intersection occurs when y ( x)= g ( x) (see the graph plot )

6 3
A new function should be defined f ( x)= y( x)− g ( x)= x − x−1+ x −5
6 3
f ( x)= x − x−1+ x −5

BDA34003 Engineering Mathematics 4 40


Waluyo Adi Siswanto ([email protected])
BDA34003 Engineering Mathematics 4 41
Waluyo Adi Siswanto ([email protected])
Result verification (freemat and smath):

BDA34003 Engineering Mathematics 4 42


Waluyo Adi Siswanto ([email protected])
Student Activity

BDA34003 Engineering Mathematics 4 43


Waluyo Adi Siswanto ([email protected])
Activity 2a

An object moves following a nonlinear function, the distance (y) is depending on the time (t)

y (x)=t 3 +2.2 t 2−8 t−16.8


a) Find the time t (positive) that the
displacement of the object at 0.
Use three different methods:
Newton-Raphson
Bisection
Secant

b) Use mathematical tools (Smath and Freemat)


to verify the results.

c) Calculate the errors (in percent) to the


Smath results.

BDA34003 Engineering Mathematics 4 44


Waluyo Adi Siswanto ([email protected])
Activity 2b

Two equations as shown below have an intersection.

a) Find the time t (positive) where the intersection


Occurs.

Use three different methods:


Newton-Raphson
Bisection
Secant

b) Use mathematical tools (Smath and Freemat)


to verify the results.

c) Calculate the errors (in percent) to the


Freemat results.

BDA34003 Engineering Mathematics 4 45


Waluyo Adi Siswanto ([email protected])
BDA34003 Engineering Mathematics 4 46
Waluyo Adi Siswanto ([email protected])

You might also like