displaying root of Newton Raphson Method
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
How to display 'iteration number 4' with value of x1??
thanks for help
Script
%clear all
%clc
x1=input('x1 = '); %value of x initial =1
Es=input ('Es = '); % value of Es = 0.5%
format long
i=0;
f=@(x) (x)^3 -9*(x)^2 +3.8197;
fd=@(x) 3*(x)^2 - 18*(x);% derivative of f(x)
while 1
f1=f(x1);
f1d=fd(x1);
x2=x1-( f1/f1d ); %Newton Raphson formula
%the iteration proceeds till certian accccuracy is attained
Ea=abs((x2-x1)/x2)*100;
f2=f(x2);
x1=x2;
if(Ea<Es)
disp('the root is ')
disp(x1);
break;
end
i=i+1;
%fprintf : This means you can format how the data is printed in
%such a manner as to make it easy to read.
fprintf('iteration number = %d\n', i)
% d stand for integer
disp('x1 = ')
disp(x1)
disp('Ea= ')
disp(Ea)
end
Comman Window:
x1 = 1
Es = 0.005
iteration number = 1
x1 =
0.721313333333333
Ea=
38.636006543619509
iteration number = 2
x1 =
0.678622946127872
Ea=
6.290737359979779
iteration number = 3
x1 =
0.677465779472787
Ea=
0.170808133804928
the root is
0.677464917281083
>>
0 comentarios
Respuestas (1)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!