0% found this document useful (0 votes)
35 views2 pages

Newton Raphson Method

The document describes using the Newton Raphson method to find the approximate root of two different functions. It defines the functions f and their derivatives df, sets the initial lower and upper bounds, and iterates the Newton Raphson method formula x1=x-(f(x)/df(x)) up to 100 times to find the approximate root. It then plots the error at each iteration to visualize convergence.

Uploaded by

Carmen Cruz
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)
35 views2 pages

Newton Raphson Method

The document describes using the Newton Raphson method to find the approximate root of two different functions. It defines the functions f and their derivatives df, sets the initial lower and upper bounds, and iterates the Newton Raphson method formula x1=x-(f(x)/df(x)) up to 100 times to find the approximate root. It then plots the error at each iteration to visualize convergence.

Uploaded by

Carmen Cruz
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/ 2

% Newton Raphson Method

clear all
close all
clc
% Change here for different functions
f=@(x) exp(x)-5*sin(2.5)-10
%this is the derivative of the above function
df=@(x) exp(x)-5*cos(2.5)
% 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')

f=

@(x)exp(x)-5*sin(2.5)-10

df =

@(x)exp(x)-5*cos(2.5)

Approximate Root is 2.564361547852220>>


% Newton Raphson Method
clear all
close all
clc
% Change here for different functions
f=@(x) 3*sin(x)-3*cos(x)-1
%this is the derivative of the above function
df=@(x) 3*cos(1)+3*sin(1)
% 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')

f=

@(x)3*sin(x)-3*cos(x)-1

df =

@(x)3*cos(1)+3*sin(1)

Approximate Root is 1.023339288227657>>

You might also like