while loop convergence problem
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tanvi
am 21 Apr. 2015
Beantwortet: Guillaume
am 22 Apr. 2015
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!
1 Kommentar
Akzeptierte Antwort
Guillaume
am 22 Apr. 2015
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!