Iteration output won't show in a plot
1 回表示 (過去 30 日間)
古いコメントを表示
Hello. I created a for loop that will give the approximated values of a square root. My problem is whenever i try to plot the output values, it just simply show an empty graph. Here is my code:
format long;
disp('Number of Iterations Approximate Value')
xData=1;
n=1;
fprintf('\n%d %.12f. \n\n',1,xData)
for n=2:5
x=0.5*(xData+2/xData);
xData=x;
fprintf('\n%d %.12f. \n\n',n,xData)
end
figure
plot(1:1:10,xData)
0 件のコメント
採用された回答
Sudhakar Shinde
2020 年 10 月 15 日
Try this:
format long;
disp('Number of Iterations Approximate Value')
xData=1;
n=1;
fprintf('\n%d %.12f. \n\n',1,xData)
for n=2:5
x=0.5*(xData(n-1)+2/xData(n-1));
xData(n)=x;
fprintf('\n%d %.12f. \n\n',n,xData)
end
figure
plot(1:1:5,xData)
2 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!