Nothing will be showing on plot
3 次查看(过去 30 天)
显示 更早的评论
% 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
0 个评论
回答(2 个)
KALYAN ACHARJYA
2021-2-23
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);
0 个评论
Rik
2021-2-23
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!