Need help plotting to different plots in the same figure from a while loop. The program calculates the results for a square root using the Newton method but it doesn't plot it.

3 ビュー (過去 30 日間)
a= input('Enter a positive number:');
ti= input('Percent of tolerance wanted:');
if a<0
disp('Number bigger than cero');
elseif ti<0
ti=ti*100;
end
k=1;
x=a/2;
t=101;
figure; hold on
while t>ti
k=k+1; %Interaction numbers
i=x; %Safes x
x=((x+(a/x))/2); %Estimates square root
t=((abs(x-i)/x)*100); %Tolerance
subplot(2,1,1); plot(k,x);
subplot(2,1,2); plot(k,t);
end
disp (['The square root is ', num2str(a), ' after ', num2str(k), ' interactions is:', num2str(x)]);

採用された回答

G A
G A 2012 年 3 月 9 日
...
figure;
clf
while t>ti
k=k+1; %Interaction numbers
i=x; %Safes x
x=((x+(a/x))/2); %Estimates square root
t=((abs(x-i)/x)*100); %Tolerance
subplot(2,1,1);
hold on
plot(k,x,'.');
subplot(2,1,2);
hold on
plot(k,t,'.');
end
hold off
disp (['The square root is ', num2str(a), ' after ', num2str(k), ' interactions is:', num2str(x)]);

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by