Nothing will be showing on plot

3 Ansichten (letzte 30 Tage)
alam md
alam md am 23 Feb. 2021
Beantwortet: Rik am 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

Antworten (2)

KALYAN ACHARJYA
KALYAN ACHARJYA am 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
Rik am 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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by