A problem with an iteration procedure

Hi everyone. I'm writing an iteration procedure that should calculate some values until the difference
X(i,j)-Y(i,j)<0.0001
where X and Y are 17by11 matrices. I have to compare each X(i,j) value with Y(i,j). I tried with a while loop with condition
max(max(err))>=0.0001
(err=X-Y) but there are some elements that don't match to the condition.
Thanks for helping and sorry for my bad english.

Risposte (2)

er=X-Y
idx=find(er<0.0001,1)
Then write your iteration:
for k=1:idx
%your code
end

1 Commento

%or maybe you want to compare
er=X-Y
if sum(abs(er))<0.0001
This is the last part of the code:
nciclo=0;
while max(max(abs(err1))) > 0.0001 | max(max(abs(err))) > 0.0001
a=anew;
a1=a1new;
for i = 1:length(r)
for j=1:n+1
fi(i,j)=(atan(x(i,j)+(((1-a(i,j)).*V(j))./((1+a1(i,j)).*omega.*r(i))))).*180./pi;
w(i,j)=omega.*r(i).*(1+a1(i,j))./cosd(fi(i,j));
alpha(i,j)=fi(i,j)-teta(i);
Re(i,j)=((ro/mu).*w(i,j))*chord(i);
cl(i,j) = interp2(Reynolds,alfa,values,Re(i,j),alpha(i,j));
cd(i,j) = interp2(Reynolds1,alfa1,values1,Re(i,j),alpha(i,j));
CT(i,j)=(sigma(i)*((1-a(i,j)).^2).*(cl(i,j).*cosd(fi(i,j))+cd(i,j).*sind(fi(i,j))))/((sind(fi(i,j))).^2);
if CT(i,j)<0.96
anew(i,j)=1/(1+((4.*F(i,j).* ((sind(fi(i,j))).^2))/(sigma(i).*cl(i,j).*cosd(fi(i,j)))));
else
anew(i,j)=(1/F(i,j)).*(0.143+sqrt(0.0203-0.6427.*(0.889-CT(i,j))));
end
a1new(i,j)=1./(((4.*F(i,j).*(cosd(fi(i,j)))./(sigma(i).*cl(i,j))))-1);
err1=(a1new-a1);
err=(anew-a);
nciclo=nciclo+1;
end
end
end

Questa domanda è chiusa.

Richiesto:

il 12 Feb 2013

Chiuso:

il 20 Ago 2021

Community Treasure Hunt

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

Start Hunting!

Translated by