필터 지우기
필터 지우기

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.

조회 수: 1 (최근 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 CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by