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

LAB 0 5

Study and implementation of programming control


feature of power system analysis in MATALB

Submitted By:Haseeb Ullah

21-EE-170

Power System Analysis Lab

Department of Electrical Engineering

University of Engineering and Technology, Taxila


 Lab no 05
Title: study and implementation of newton raphson method for
the solution of equation using matlab.

Objective:

• TO learn about newton raphson method


• To implement this in matlab

Theoretical Background:

Newton-Raphson method, also known as the Newton method, is an iterative numerical technique
for finding successively better approximations to the roots (or zeroes) of a real-valued function. It's
particularly useful when an analytical solution to finding these roots is difficult or impossible to
obtain. The method is based on the concept of using tangent lines to approximate the behavior of a
function near a root. Given an initial guess, the method iteratively refines this guess by intersecting
the x-axis with the tangent line at that point. The point of intersection becomes the new
approximation, hopefully closer to the true root.

• Mathematical model of newton-raphson method:


Newton-raphson mathematical model can be of a function f(x) as;
Xn+1=xn-f(x)/f’(x)
Or xn+1=0-f(x)/f’(x)
Where f(x) is a function or equation and f’(x) is it’s derivative.

• Advantages of newton-raphson method:

(1) Rapid convergence with close initial guesses.


(2) Efficient computation with simple arithmetic operations.
(3) Quadratic convergence for highly accurate solutions.
(4) Versatility for various numerical problems.
(5) Utilizes analytical derivatives when available.
(6) Self-correcting nature adapts to function behavior.
(7) Well-studied and reliable in numerical analysis.
• limitation of newton-raphson method:
(1) Requires a close initial guess for convergence.
(2) Sensitivity to function behavior near the root.
(3) Dependency on the availability and accuracy of function derivatives.
(4) Risk of division by zero.
(5) Potential convergence to local extrema.
(6) Limited applicability to certain functions or systems.
(7) Convergence not always guaranteed.

Mathematical steps:

(1) Start: Begin with an initial guess x0.


(2) Evalute f(x0) and f’(x0).
(3) Update the guess using the formula xn+1=0-f(xn)/f’(xn) to calculate the next approximation xn+1.
(4) Repeat steps 2 and 3 until the desired level of accuracy is achieved or until convergence criteria
are met.

Pseudo code:

1. Clear the console, variables, and plots


2. Define symbolic variable x
3. Set initial values:
dx = 1
x_val = 2
iter = 0
4. Display the column headers for the output table
5. While absolute value of dx is greater than or equal to 0.001 and iter is less than 10, do:
a. Increment iter by 1
b. Compute g = -f(x_val) where f(x) is the given function
c. Compute y = f'(x_val), the derivative of f(x) with respect to x
d. Compute dx = g / y
e. Update x_val = x_val + dx
f. Print the current iteration number, g, dx, and x_val
6. End of loop

Flow chart:
LAB TASK

Use Newton-Raphson method to develope the code for the f(x)= x^3 - 6*x^2 + 9*x – 4.

Matlab Code:

clc

clear all

close all

syms x;

dx = 1;

x_val = 2;

iter = 0;

disp('iter g dx x')

while abs(dx) >= 0.001 && iter < 10

iter = iter + 1;

g = -subs(x^3 - 6*x^2 + 9*x - 4, x, x_val);

y = subs(diff(x^3 - 6*x^2 + 9*x - 4), x, x_val); % differentiate the function

dx = g / y;

x_val = x_val + dx;

fprintf('%d', iter)

disp([double(g), double(dx), double(x_val)])

end
Command window:

iter g dx x

1 2.0000 -0.6667 1.3333

2 0.2963 -0.1778 1.1556

3 0.0688 -0.0800 1.0756

4 0.0167 -0.0383 1.0373

5 0.0041 -0.0188 1.0185

6 0.0010 -0.0093 1.0092

7 0.0003 -0.0046 1.0046

8 0.0001 -0.0023 1.0023

9 0.0000 -0.0012 1.0012

10 0.0000 -0.0006 1.0006

Conclusion:

The implemented Newton-Raphson method successfully approximates the root of the equation f(x)=
x^3 - 6*x^2 + 9*x – 4. With close initial guesses, the method rapidly converges towards the root,
demonstrating its efficiency and versatility in numerical computation. However, it requires careful
selection of initial guesses and may exhibit sensitivity to function behavior near the root. Overall, the
method's reliance on function derivatives and potential for local extrema necessitate cautious
application in various numerical problems.

You might also like