while loop convergence problem

2 ビュー (過去 30 日間)
Tanvi
Tanvi 2015 年 4 月 21 日
回答済み: Guillaume 2015 年 4 月 22 日
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 件のコメント
Greg Heath
Greg Heath 2015 年 4 月 22 日
Please format your code.

サインインしてコメントする。

採用された回答

Guillaume
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 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by