Need help altering code to so it records all values, not just the final ones.
Show older comments
Hello, I need help putting all of the i, xi, and Err values in a table with the column headers "Iteration Number", "xi", and "Error".
% 4)Use Newton Raphson's method with intial guess of 4.5
% to find one of the roots. The stop condition is error<0.1%.
% part
%Err=relative approx error
%xi=initial guess
%y=function
%der=derivative
%i=iteration number
fprintf(' \n 4) Newton Raphsons Method \n')
fprintf(' \n a) Initial guess of 4.5 \n')
Err=1;
xi=4.5;
i=0;
while Err>.001
y=(0.5*xi.^3)-(4*xi.^2)+(6*xi)-1;
der=1.5*xi.^2+8*xi+6;
xii=xi-(y/der);
Err=abs((xii-xi)/(xii));
xi=xii;
i=i+1;
end
disp('Root is');
disp(xi);
disp('Relative Approximation Error');
disp(Err);
Accepted Answer
More Answers (1)
Categories
Find more on Newton-Raphson Method in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!