Non Linear Equations By NR Method Matlab Code - Matlab Simulink for E & T

# Matlab Code / Program to solve Non Linear Equations By Newton – Raphson Method

## Newton – Raphson method –

NR technique for finding successively better approximations to the roots of a function.

Consider f(y) of one variable y and its derivative f ’(y). And it’s initial estimate y0.

If function is rationally well performed a superior estimate y1 is

y1 = y0 – f(y0) / f `(y0)

where y1 is the intersection point of the tangent line

This procedure is repetitive while waiting for a appropriately precise value is reached

After n iteration we find

yn+1 = yn – [ f(y0) / f `(y0) ]

In this NR method we start with an preliminary estimate y0 which is rationally adjacent to the accurate root

For best laptop for Matlab software-  https://amzn.to/39QeZ9d

Camera- https://amzn.to/39KBi02

Professional tripod- https://amzn.to/39Jg96w

This y interrupt will be a superior guesstimate to the root of the function

Than the original estimate and the process can be further repeated.

The succeeding procedure can be trailed for resolving a problem by NR technique.

### Step – 1

Take an initial guess y0 and evaluate f `(y) , i.e. find the first derivative of the function f(y) with respect to y

### Step – 2

Calculate estimate of the root

yi+1 = [ f(y0) / f `(y0) ]

and absolute relative approximate error which is

| Error | = | (yi+1 – yi) / yi+1 | × 100

### Step – 3

Find

if ( absolute relate approximation error is > pre -specified relative error) tolerance

### Step – 4

If

so go to step - 2

else

stop the algorithm

### Step – 5

check

number of repetitions (iteration) ought to not beat the extreme number of repetitions (iteration)

Example -

finds the roots of this non - linear equations by NR method

y12 - y22 + y32 – 10 = 0

y1y2 + y22- 4y3 - 4 = 0

y1 - y1y3 + y2y3 – 5 = 0

Ø open the editor window in matlab (shortcut key CTRL+N)

Ø write down the following matlab code in editor window

Matlab Code / Program -

clc ;

clear all ;

close all ;

%- - - By - Matlab Simulink for Enginnering & Tech. - - - - -

% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

% This Code for solves to three Nonlinear equations by N R Method

% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

%   Let us take three nonlinear equations as: - - - - - - - -

% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

%  E1 = (y1)^2 - (y2)^2 + (y3)^2 - 10 = 0          ( 1st equation)

%  E2 = (y1) * (y2) + (y2)^2 - 4(y3) - 4 = 0       ( 2nd equation)

%  E3 = (y1)- (y1) * (y3) + (y2) * (y3) - 5 = 0    ( 3rd equation)

% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

% - - - - - - - - - - - - - - - - - - - - - - - - -

%  Let the initial conditions be y1 = y2 = y3 = 1 :

% - - - - - - - - - - - - - - - - - - - - - - - - -

% - - - - - - - - - - - - - - - - - - - - - - - - -

% The Jacobian matrix of the above equations is: --

% - - - - - - - - - - - - - - - - - - - - - - - - -

% - - - - - - - - - - - - - -

% Jm = [2y1  -2y2     2y3     ;

%     y2   y1+2y2   -4

%     1-y3   y3    -y1+y2];  ;

% - - - - - - - - - - - - - -

y = [1;1;1]; % Initial conditions

Initial = 1 ;

iter = 0 ;

while Initial > 1e-6

E = [y(1)^2 - y(2)^2 + y(3)^2 - 10 ;

y(1) * y(2) + y(2)^2 - 4*y(3) - 4 ;

y(1) - y(1) * y(3) + y(2) * y(3)- 5 ] ;

Jm = [2*y(1) -2*y(2) 2*y(3);y(2) y(1)+2*y(2) -4;1-y(3) y(3) -y(1)+y(2)];

iniy = -inv(Jm)* E ;

y = y + iniy ;

Initial = max(abs(E)) ;

iter = iter + 1 ;

end

disp('The Result congregates in repetitions') ,

iter ,

pause

disp(' Ultimate final values of variable y - are '),

y

Ø After complete write code then save the code and run

Ø for run press F5 key and output show in command window

Matlab Result / Output -

The Result congregates in repetitions

iter =

7

Ultimate final values of variable y - are

y =

2.5870

3.2369

3.7128

Related Post –

# Gauss Seidal Method

For more MATLAB Code and program

Please Like, Comment, follow our blog for new updates and Share and email subscribe for latest update

! THANK YOU !