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!