Newton Raphson Method Matlab Code - Applications - Drawbacks


What is Newton Raphson Method: Newton Raphson is a normal method which starts with a primary estimate of the root to solve a non-linear equation by finding the root of the equation. One of the easiest things about this method that it is only used multiplication and subtraction operations. Newton Raphson method is implemented in this post by solving a non-linear equation f(x)=cos(x)-3x+1.


Application of Newton Raphson Method:

  1. Its use is limited. This method is usually used for solving a non-linear equation.
  2. And to find the root of that equation.
  3. It can be used as usual as the bisection method to find the orbits of a molecular system.

Majors Drawback of Newton Raphson Method:

  1. Divergency of the inflections points in a non-linear equation curve.
  2. The solution process is stopped by the division by zero property.

Newton Raphson Method Matlab Code:


-------------start---------------


%clearing the session of matlab before running this program

 clear all

 close all

 clc

 % solution for f(x)=cos(x)-3x+1 function

 f=@(x)cos(x)-3*x+1

 %this is the derivative of the f(x)=cos(x)-3x+1 function

 df=@(x)-sin(x)-3

 % Change lower limit 'a' and upper limit 'b'

 a=0; b=1;

 x=a;

 for i=1:1:100

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

    x=x1;

 end

 sol=x;

 fprintf('Approximate Root is %.15f',sol)

 a=0;b=1;

 x=a;

 er(5)=0;

 for i=1:1:5

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

    x=x1;

    er(i)=x1-sol;

 end

 disp(er)

 plot(er, '-- bs')

 xlabel('Number of iterations')

 ylabel('Error')

 title('Error Vs. Number of iterations')


-------------end---------------


Outputs:


Error vs Number of iteration


Post a Comment

Previous Post Next Post