NM - 03b Non Linear Eq - New1

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

CHAPTER 03

PENYELESAIAN PERSAMAAN NON LINEAR NEWTON RAPHSHON

Newton-Raphson Method
This method is more efficient than the Bisection and Iteration methods. If x is the real root and x0 is an initial approximation of the real root of an equation f(x) = 0, f (x0) 0, f(x) has the same sign between x0 and x, Then, the tangent at f(x0) can lead to the real root x.
2

Newton-Raphson Method: Geometric Significance


f(x0)

tangent at f(x0)

The initial guess f(x1)


3

Newton-Raphson Method: Geometric Significance


Here, The slope at x0 is tan (PTM) tan (PTM) = PM/TM tan (PTM) = f (x0)/h Again, tan (PTM) = f (x0) Therefore, f (x0) = f (x0)/h Or, h = f (x0)/ f (x0) x1 = x0 h Therefore, x1 = x0 f (x0)/ f (x0) Similarly, x2 = x1 f (x1)/ f (x1)

Newton-Raphson Method
Methodology Let x0 be an approximate root of f(x) = 0 and Let, x1 is the correct root such that x1 = x0 + h and f(x1) = 0. Expanding f(x0+h) by Taylors series, we obtain,

h2 f ( x0 ) + hf ( x0 ) + f ( x0 ) + ... = 0 2!
Neglecting the second and higher order derivatives, we have Which gives

f ( x0 ) + hf ( x0 ) = 0
f ( x0 ) h= f ( x0 )

Newton-Raphson Method (Contd.)


A better approximation than x0 is therefore given by x1 where

f ( x0 ) x1 = x0 + h = x0 f ( x0 )
Successive approximation are given by x2, x3, .., xn, xn+1 where

f ( xn ) xn +1 = xn f ( xn )
This formula is known as the Newton-Raphson formula.

Newton-Raphson Method
f(x)

f(xi)

[x f (x )]
i, i

f(xi ) xi +1 = xi f (xi )
f(xi-1) xi+2 xi+1 xi X

Figure 1 Geometrical illustration of the Newton-Raphson method.


7 http://numericalmethods.eng.usf.edu

Derivation
8

f(x)

f(xi)

tan( ) =

AB AC

f ( xi ) f ' ( xi ) = xi xi +1
C xi+1 A xi X

f ( xi ) xi +1 = xi f ( xi )

Figure 2 Derivation of the Newton-Raphson method.


http://numericalmethods.eng.usf.edu

Algorithm for Newton-Raphson Method

http://numericalmethods.eng.usf.edu

Step 1

Evaluate

f (x)

symbolically.

10

http://numericalmethods.eng.usf.edu

Step 2

Use an initial guess of the root, xi , to estimate the new value of the root, xi +1, as

f ( xi ) xi +1 = xi f (xi )

11

http://numericalmethods.eng.usf.edu

Step 3
Find the absolute relative approximate error a as

xi +1- xi a = 100 xi +1

12

http://numericalmethods.eng.usf.edu

Step 4
Compare the absolute relative approximate error with the pre-specified relative error tolerance s .
Yes Is a >s? No Go to Step 2 using new estimate of the root. Stop the algorithm

Also, check if the number of iterations has exceeded the maximum number of iterations allowed. If so, one needs to terminate the algorithm and notify the user.
13 http://numericalmethods.eng.usf.edu

Newton-Raphson Method: Example


Find the real root of the equation using NewtonRaphsons Method f(x)= x3 + 4x2 1= 0, f(x) = 3x2 + 4*2x - 0 3 2 xn + 4 xn 1 f ( xn ) xn +1 = xn = xn 2 f ( xn ) 3 xn + 8 x
x0 x1 x2 x3 x4
14

0.5 0.473684211 0.472834787 0.472833909 0.472833909

Example

You are working for DOWN THE TOILET COMPANY that makes floats for ABC commodes. The ball has a specific gravity of 0.6 and has a radius of 5.5 cm. You are asked to find the distance to which the ball will get submerged when floating in water.

15

Solution
The equation that gives the depth x to which the ball is submerged under water is given by

f ( x ) = x 3-0.165 x 2+3.993x10- 4 f ( x ) = 3x 2-0.33x


Use the Newtons method of finding roots of equations to find the depth x to which the ball is submerged under water. Conduct three iterations to estimate the root of the above equation.

16

Graph of function f(x)


17

f ( x ) = x -0.165 x +3.993x10
3 2

-4

http://numericalmethods.eng.usf.edu

Iteration #1
18

x0 = 0.02

f ( x0 ) x1 = x0 f ' ( x0 ) 3.413x104 x1 = 0.02 5.4 x103 = 0.08320 a = 75.96%

Iteration #2
19

x1 = 0.08320 x2 = x1

f ( x1 ) f ' ( x1 )

1.670x104 x2 = 0.08320 6.689 x103 = 0.05824 a = 42.86%

Contoh Program
Penyelesaian dgn fzero
function newraph_o x0=0.02; x=fzero(@fungsi, x0,optimset('display','off')) function y=fungsi(x) y=x^3-0.165*x^2+0.00039

Penyelesaian dgn algoritma Newton Raphshon


%contoh metode newton raphshon %akan dicari harga x dari persamaan x^3+4*x^2-1=0 clear clc % xold=2; % tol=0.00001; xold=input('harga awal utk memulai perhitungan tol=input('toleransi '); xnew=0; delta=abs(xold-xnew); while delta>=tol xnew=xold-(xold^30.165*xold^2+0.0003994)/(3*xold^2-0.33*xold); delta=abs(xold-xnew); if delta>=tol xold=xnew; end end hasil=(xold+xnew)/2 % hasil % disp(['harga x yang memenuhi persamaan adalah ',num2str((xold+xnew))/2])

');

Advantages
21

Converges fast, if it converges Requires only one guess

Mulai

Definisikan f(x) dan f(x), x0, tol

Nyatakan: x = x0 x0 = x + 1

tidak |(x-x0)/x|>tol ya Nyatakan: x0 = x


Tampilkan x* = x

Hitung harga: f(x0) dan f(x0)

Selesai

Hitung harga: x=x0-f(x0)/f(x0)

Function
function fx=f_cth_NR_01(x) fx=x^3-1; Catatan: Program yang ditulis dalam MATLAB disimpan dalam mfile. Ada 2 jenic m-file: -script m-file -function m-file

Matlab: Nonlinear Algebraic Equations

fzero

Matlab function for solving a single nonlinear algebraic equation Finds the root of a continuous function of one variable Syntax: x = fzero(fun,xo)

fun is the name of the user provided Matlab m-file function (fun.m) that evaluates and returns the LHS of f(x) = 0 xo is an initial guess for the solution of f(x) = 0

Algorithm uses a combination of bisection, secant, and inverse quadratic interpolation methods Function for solving a system of nonlinear algebraic equations Only available in Matlab Optimization Toolbox Discussed next lecture

fsolve

MATLABs fzero Function

MATLABs fzero provides the best qualities of both bracketing methods and open methods.

Using an initial guess: x = fzero(function, x0) [x, fx] = fzero(function, x0)


function is a function handle to the function being evaluated x0 is the initial guess x is the location of the root fx is the function evaluated at that root

Using an initial bracket: x = fzero(function, [x0 x1]) [x, fx] = fzero(function, [x0 x1])

As above, except x0 and x1 are guesses that must bracket a sign change

fzero Options

Options may be passed to fzero as a third input argument - the options are a data structure created by the optimset command
options = optimset(par1, val1, par2, val2,)

the name of the parameter to be set valn is the value to which to set that parameter The parameters commonly used with fzero are:

parn is

display: when set to iter displays a detailed record of all the iterations tolx: A positive scalar that sets a termination tolerance on x.

fzero Example

options = optimset(display, iter);


Sets

options to display each iteration of root finding process

[x, fx] = fzero(@(x) x^10-1, 0.5, options)


Uses

fzero to find roots of f(x)=x10-1 starting with an initial guess of x=0.5.

MATLAB reports x=1, fx=0 after 35 function counts

Penyelesaian persamaan nonlinear dengan fsolve

Program utama: x0 = 3; x = fsolve(@myfun, x0)

function F = myfun(x) F =x^3-1;

Nama fungsi

Harga awal

Contoh

Misal f(x)=x3-1 x=... f(x) = 3x2


xold 2 1.011

f ( xold ) xnew = xold f ' ( xold )


xnew

Iterasi ke1 2 3 4

2-(23-1)/(3x22) = 1.4167 (not OK) 1.011 -(1.0113-1)/(3x 1.0112) = 1.0001 (not OK)

1.4167 1.4167 -(1.41673-1)/(3x1.41672) = 1.011 (not OK) 1.0001 1.0001 -(1.0001 3-1)/(3x 1.0001 2) = 1.0000001 (OK)

Contoh aliran fluida


Subroutine Program
function f=rey(v) rho=1; miu=0.01; g=981; z1=300; z2=800; d=4; le=20000; q=22/7/4*d^2*v; hm=3718.5-2.3496*q+7.847401E-4*q^2-9.5812E8*q^3; re=rho*v*d/miu; fi=0.0596/re^0.215; f=z2-z1+fi*le*v^2/(2*g)-hm; fprintf('nilai harga Q= %6.4f cm3/s\n',q)

Main Program
v0=500; v=fsolve(@rey,v0,optimset(@fsolve)); fprintf('nilai v ketemu= %6.4f cm/s',v)

You might also like