You are on page 1of 3

Numerical Analysis Lab

Lab No.11

Submitted By:
Muhammad Hassan (2020-MC-274)
Submitted to:
Dr. Arshi Khalid
--------------------------------------------------------------------------------------------------------
-

Department of Mechatronics & Control Engineering


University of Engineering & Technology Lahore,
Faisalabad Campus.
Lab report By: M.Hassan (2020-MC-274) Submitted To: Dr. Arshi Khalid

Lab Objective:
Implement the following Root Finding Methods on the Matlab.

 To create a program for Newton Raphson Method.

 Newton Raphson Method:


The Newton-Raphson method (also known as Newton's method) is a way to quickly find a
good approximation for the root of a real-valued function f(x) = 0f(x)=0. It uses the idea that a
continuous and differentiable function can be approximated by a straight line tangent to it.

Formula For New Point:

xn+1=xn − f′(xn)/f(xn)

Algorithm For Newton-Raphson Method:

1. Compute f′(xn).
2. Choose an appropriate initial guess x0.
3. Apply the next point formula and calculate the next points until the difference of x(n+1) – x(n) ≈ 0.
Matlab Code:
% Newton Raphson Method
clc;
clear;
syms x;
f(x) = input('\nPlease Enter the Function without function handler.\nEnter the
function: ');
% to differentiate the input function w.r.t to x
g(x) = diff(f(x),x);
% to take the initial guess
a = 0;
b = 1;
while ((f(a)*f(b))>0)
a = a+1;
b = b+1;
end
x(1) = (a+b)/2;
x(2) = x(1) - (f(x(1)))/(g(x(1)));
n = 3;
while (((x(n-1) - x(n-2)) > 0.00001) || ((x(n-1) - x(n-2)) < -0.00001))
x(n) = x(n-1) - (f(x(n-1)))/(g(x(n-1)));

2
Lab report By: M.Hassan (2020-MC-274) Submitted To: Dr. Arshi Khalid

n = n+1;
end
fprintf('\nRoot from Newton-Raphson Method is: \t%f\n',x(n-1));

Output:

You might also like