# Nothing will be showing on plot

14 views (last 30 days)
alam md on 23 Feb 2021
Answered: Rik on 23 Feb 2021
% Solve the problem using netwon raphson method
% f(x)=x^10-1
clc;clear
% Start the computation
xo=0.65;
x=xo;
xold=x;
for iteration=1:22
x=xold;
fx =x^10-1;
der_x=10*x^9;
y=fx./der_x;
xnew=x-y;
xold=xnew;
err=abs(xnew-x);
disp([' Iteration number : ' , num2str(iteration) , ' ; The new value of the x is : ' , num2str(xnew), ' ; The error is : ' , num2str(err) ])
plot(iteration,err)
end

KALYAN ACHARJYA on 23 Feb 2021
xo=0.65;
x=xo;
xold=x;
iteration=1:22;
err=zeros(1,length(iteration));
for i=1:length(iteration)
x=xold;
fx =x^10-1;
der_x=10*x^9;
y=fx./der_x;
xnew=x-y;
xold=xnew;
err(i)=abs(xnew-x);
disp([' Iteration number : ' , num2str(iteration) , ' ; The new value of the x is : ' , num2str(xnew), ' ; The error is : ' , num2str(err) ])
end
plot(iteration,err);

Rik on 23 Feb 2021
You are plotting single points, without changing the default (where points are not displayed, only the line connecting them). You are also resetting the plot, as you don't use hold.
You should store the results of your calculation in a vector so you can use that in plot.