July 9th, 2009, 12:55 pm
I have the following problem, I need traslate this function of MAtlab to visual basic, can someone help me with this? I will appreciate all help in this matterfunction [P_LR, pi_LR, Moments ] = LR_distr(P,pi0,S)% DistributionMax_Iter = 500; %mximum iterationsconverg = 1.e-5;Pk = P; %initialize Pkfor i = 1 : Max_Iter %loop to find the invariant P, i.e. P_LR Precord = Pk; Pk = Pk*P;% if norm( Pk - Precord, Inf )< converg; display('Q converged'); P_LR=Pk; break; end if norm( Pk - Precord, Inf )< converg; P_LR=Pk; break; endend if norm( Pk - Precord, Inf )>= converg; P_LR=[]; pi_LR=[]; display('Q didn`t converge; Increase Max_Iter'); else pik = pi0; %initialize pik for i = 1 : Max_Iter %loop to find the invariant pi, i.e. pi_LR pirecord= pik; pik = P'*pik;% if norm( pik - pirecord, Inf )< converg; display('pi converged'); pi_LR=Pk(1,: )'; break; end if norm( pik - pirecord, Inf )< converg; pi_LR=Pk(1,: )'; break; end end if norm( pik - pirecord, Inf )>= converg;; display('pi didn`t converge; Increase Max_Iter'); end; [V,D] = eig(P'); %obtain number of invariant distributionsnumeig = 0; %count # of positive eigenvalues PI = []; %initialize matrix of distributionsfor i=1:size(P,1); if abs(D(i,i)-1) < converg, numeig = numeig + 1; PI(:,numeig) = V(:,1)/sum(V(:,i)); endend display({'# of invariant distr = %d', numeig});Moments(1,1) = S'*pi_LR;%(1,: )'; %unconditional mean%Moments(2,1) = sum( (S - (S'*pi_LR)).^2.*pi_LR); %unconditional varianceMoments(2,1) = sqrt(pi_LR'*((S - Moments(1,1)).^2)); %unconditional varianceend %this closes the "else" on line 26