while loop convergence problem
조회 수: 3 (최근 30일)
이전 댓글 표시
i am writing a program to separate my mixed images using neural learning algorithm.i have a program instead of looping 100 times i want it to loop until (v*v') becomes identity matrix.
here's my code so far:-
clc;
clear all;
i1=imread('cameraman.tif');
i2=imresize(i1,[256 256]);
p1=reshape(i2,[1 65536]);
i3=imread('moon.tif');
i4=imresize(i3,[256 256]);
p2=reshape(i4,[1 65536]);
i5=imread('trees.tif');
i6=imresize(i5,[256 256]);
p3=reshape(i6,[1 65536]);
p=[p1;p2;p3];
a=unifrnd(-1,1,3,3);
mix=a*double(p);
m=mean(mix(:));
c=minus(mix,m);
c1=-1+2*((c-min(min(c)))/(max(max(c))-min(min((c)))));
n=.0000000001;
V=orth(unifrnd(-1,1,3,3));
I=eye(3,3);
con=0;
epoch=0;
while(con==0)
v=V*c1;
V=V+n*(I-v*v');
epoch=epoch+1;
if(epoch==2)
break;
end
end
kindly help me. thank you!
채택된 답변
Guillaume
2015년 4월 22일
You just need to replace your if condition inside your loop.
while true
%... code that calculate V
if isequal(V*V', eye(size(V))
break;
end
end
Note that with the above will only stop the loop if V*V' is exactly the identity matrix. Small errors due to floating point precision may not make it true, so you may be better off with:
while true
%... code that calculate V
delta = V*V' - eye(size(V));
if max(abs(delta(:))) < 1e-10 %or whatever tolerance you want
break
end
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!