Newton Raphson Method MATLAB code (Program) with simple Example

10 May

Newton Raphson Method MATLAB code :

Introduction to Iterative methods:

There are a number of iterative methods like  Jacobi method, Gauss–Seidel method that have been tried and used successfully in various problem situations. All these methods typically generate a sequence of estimates of the solution which is expected to converge to the true solution.

Newton Raphson method is also one of the iterative method which is used to find the roots of given expression.

Newton Raphson Method with MATLAB code:

If point x0 is close to the root α, then tangent line to the graph of f(x) at x0 is a good approximation the f(x) near α. So root of the tangent line, where line cuts the X-axis; x1 is the better approximation to α than x0 is.

Slope of the tangent = 

1

Therefore 2

Repeating process, we obtain a better approximation,3

Continue in this way. If xn is the current estimate, then the next estimate xn+1 is given by

4

if x0 is sufficiently close to α, xn→α as n→∞.

Limitations of Newton Raphson method:

  1. If initial guess is too far away from the required root, the process may converge to some other root.
  2. Division by zero may occur if f’(xi) is zero or very close to zero.
  3. A particular value in the iteration sequence may repeat, resulting in an infinite loop.

Newton Raphson MATLAB program : 

% Newton Raphson Method
clear all
close all
clc
% Change here for different functions
f=@(x) cos(x)-3*x+1
%this is the derivative of the above 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
plot(er)
xlabel(‘Number of iterations’)
ylabel(‘Error’)
title(‘Error Vs. Number of iterations’)

ANSWER :
f =
@(x)cos(x)-3*x+1
df =
@(x)-sin(x)-3
Approximate Root is 0.6071016481031231

Newton Raphson MATLAB program

Newton Raphson MATLAB program

You may also like:

Tags: Newton Raphson Method MATLAB code, Newton Raphson Method MATLAB program.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 239 other followers

%d bloggers like this: