Solving Newton Raphson Method
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I do not know how to add x1,x2,x3,x4 in my code!? And in command window "iteration number 4 appears with no Ea"!? , so please I appreciate any help for me and my friends in this project
%clear all
%clc
x1=input('x1 = '); %value of x initial =1
Es=input ('Es = '); % value of Es = 0.5%
i=1;
f=@(x) (x)^3 -9*(x)^2 +3.8197;
fd=@(x) 3*(x)^2 - 18*(x);% derivative of f(x)
while i<4
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;
disp('Ea= ')
disp(Ea)
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
end
break
Command Window:
x1 = 1
Es = 0.005
Ea=
38.636006543619509
iteration number = 2.
Ea=
6.290737359979779
iteration number = 3.
Ea=
0.170808133804928
iteration number = 4.
>>
0 Kommentare
Antworten (1)
Jan
am 24 Dez. 2020
This is the expected behavior:
while i<4
disp('Ea = ');
i = i + 1;
fprintf('iteration number = %d.\n', i);
end
This stops after displaying the message "iteration number = 4."
What does "add x1,x2,x3,x4" mean?
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!