フィルターのクリア

why is my plot not showing?

1 回表示 (過去 30 日間)
Luis Garcia
Luis Garcia 2018 年 2 月 13 日
コメント済み: Luis Garcia 2018 年 2 月 13 日
Im trying to plot iteration on the x-axis vs error_delta on the y-axis, but nothing shows, they are inside the while loop.
%root for f(x) = cos(x)
paso = 0.5e-10;
N = 100;
x= 1.0; %initial guess.
i = 0;
eps = 1;
root_delta = 4.6;
figure(1);
hold on;
while eps >= paso && i <= N
y = x - (cos(x)/(-sin(x)));
eps = abs(y-x);
x= y;
error_delta = abs(root_delta - x);
i = i+1;
disp(' root iteration');
disp([x',i',error_delta']);
semilogy(i,error_delta);
xlabel('iterations');
ylabel('error Delta');
end
disp(y);
disp(i);

採用された回答

Walter Roberson
Walter Roberson 2018 年 2 月 13 日
i = i+1;
error_delta(i) = abs(root_delta - x);
semilogy(1:i,error_delta);
drawnow()
  1 件のコメント
Luis Garcia
Luis Garcia 2018 年 2 月 13 日
Thank you so much! I gladly appreciate it.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2018 年 2 月 13 日
You need to index x and y. You're just overwriting the same scalar values so there is never an array to plot.
  1 件のコメント
Luis Garcia
Luis Garcia 2018 年 2 月 13 日
so error_delta = 0; but x is the i(for this plot), and I taught i was index at 0 already.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by