Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views4 pages

Numerical 4

The document outlines an experiment focused on solving non-linear equations using the Newton Raphson and Secant methods in MATLAB. It details the objectives, theoretical background, algorithms, MATLAB code, and outputs for both methods, demonstrating their effectiveness in achieving convergence to the root. The experiment concludes that both methods are practical for numerically solving non-linear equations, with considerations for computational efficiency and implementation ease.

Uploaded by

abirsrk8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Numerical 4

The document outlines an experiment focused on solving non-linear equations using the Newton Raphson and Secant methods in MATLAB. It details the objectives, theoretical background, algorithms, MATLAB code, and outputs for both methods, demonstrating their effectiveness in achieving convergence to the root. The experiment concludes that both methods are practical for numerically solving non-linear equations, with considerations for computational efficiency and implementation ease.

Uploaded by

abirsrk8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment No: 04

Experiment Name: Solving non-linear equations using Newton Raphson Method and Secant
Method
Objectives:
1. To apply the Newton Raphson Method & Secant Method to solve non-linear equations in
MATLAB.
2. To develop MATLAB code to implement the Newton Raphson Method & Secant Method
algorithm.
3. To display each iteration's approximations, root, and error by Newton-Raphson and Secant
methods in tabular form.
Theory:
There are two types of methods to solve non-linear equations:
1. Bracketing Method. (Ex. Bisection Method)
2. Non-bracketing Method. (Ex. Newton Raphson Method, Fixed point iteration Method,
Gaussian Method)
The Newton-Raphson method which is also known as Newton’s method, is an iterative
numerical method used to find the roots of a real-valued function. Method or Newton’s Method
is an algorithm to approximate the roots of zeros of the real-valued functions, using guess for the
first iteration (x0) and then approximating the next iteration(x1) which is close to roots.
The secant method is a root-finding procedure in numerical analysis that uses a series of roots of
secant lines to better approximate a root of a function f. The secant method can be thought of as
a finite-difference approximation of Newton's method.
The Newton Raphson Method & Secant Method will be applied in this experiment to solve a
non-linear equation given below,
f ( x ) = x 3−x−1
4.5 Algorithm:
4.5.1 Newton Raphson Method:
Step 1: Define the symbolic variable 𝑥 and the function 𝑓(𝑥).
Step 2: Define first derivative of f(x) as df
Step 3: Initialize the initial guess for the root, x=1.
f ( xi )
Step 4: Set, x 1=x−
f ' ( xi )
Step 5: Calculate the error as | x 1- x|

Step 6: Set x = x 1

Step 7: Repeat steps 4-6 until | x 1- x| < 0.001


4.5.2 Secant Method:
Step 1: Define the symbolic variable 𝑥 and the function 𝑓(𝑥).
Step 2: Initialize the initial guesses for the root, x0 = 1 and X 1 = 1.1.

Step 3: Compute the values of 𝑓(𝑥) at the current guesses x0 and x1.
f ( X 1 ) ( X ¿ ¿ 1− X 0 )
Step 4: Set, X 2 =X 1− ¿
f ( X 0 ) −f ( X 1 )

Step 5: Calculate the error as | x 2- X 1 |

Step 6: Set, , X 0 = X 1 , X 1 = X 2

Step 7: Repeat steps 3-6 until | x 2- X 1 |< 0.001

4.6 MATLAB Code & Output:


4.6.1 Newton Raphson Method:
clc
clear
syms x;

f=@(x)( x 3−x−1);

df=diff(f);
x=1;

fprintf('Iteration \t x \t\t f(x)\t\t \t\t Error\


n')

for i=1:100;

xdf=vpa(subs(df));

x1=x-(vpa(subs(f))/vpa(subs(df)));

if i==1
error=inf;
else
error=abs(x1-x);
end

x=x1;

fprintf('\t%d \t %f \t %f \t %f \n',i,x,f(x), error);

if error<=0.001;
break;
end

Output:

Iteration x f(x) Error


1 1.500000 0.875000 Inf
2 1.347826 0.100682 0.152174
3 1.325200 0.002058 0.022626
4 1.324718 0.000001 0.000482

4.6.2 Secant Raphson Method:


clc;
clear all;

syms x;
f(x) =(x^3-x-1);

x0 = 1;
x1 = 1.1;

fprintf('Iteration \t x \t\t f(x)\t\t \t\t Error\


n')

for i = 1:100
fx0 = double(subs(f, x, x0));
fx1 = double(subs(f, x, x1));

x2 = x1 - ((x1 - x0) / (fx1 - fx0)) * fx1;

if i == 1
error = inf;
else
error = abs(x2 - x1);
end
x0 = x1;
x1 = x2;

fprintf('\t%d \t %f \t %f \t %f \n', i, x2, double(subs(f, x,


x2)), error);

if error <= 0.001


break;
end
end

Output:
Iteration x f(x) Error
1 1.432900 0.509136 Inf
2 1.300292 -0.101811 0.132608
3 1.322391 -0.009904 0.022099
4 1.324772 0.000230 0.002381
5 1.324718 -0.000000 0.000054

4.7 Discussion & Conclusion:


The non-linear equation, f ( x ) = x 3−x−1 was successfully solved in MATLAB using the
Newton-Raphson and Secant methods. Convergence to the root within a tolerance of 0.001 was
achieved after several iterations by both methods. The initial guesses were iteratively refined
using function derivatives in the Newton-Raphson method resulting in rapid convergence.
Similarly, successive function values were utilized to approximate the root in the Secant method
resulting in slightly slower convergence. Despite differences, the practicality of both methods in
numerically solving non-linear equations was showcased. Consideration between methods was
influenced by factors such as computational efficiency and ease of implementation. Overall, the
versatility and efficacy of numerical methods for solving non-linear equations in MATLAB were
demonstrated in this experiment.

You might also like