Hi User
I am stack in try to translate a Matlab code to visual basic, someone can help me with this I appreciate a lot your help
Thanks in advance
HTML Code:function [P_LR, pi_LR, Moments ] = LR_distr(P,pi0,S) %COMPUTE THE INVARIANT DISTRIBUTIONS Max_Iter = 500; %mximum iterations converg = 1.e-5; Pk = P; %initialize Pk for 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; end end 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 distributions numeig = 0; %count # of positive eigenvalues PI = []; %initialize matrix of distributions for i=1:size(P,1); if abs(D(i,i)-1) < converg, numeig = numeig + 1; PI(:,numeig) = V(:,1)/sum(V(:,i)); end end display({'# of invariant distr = %d', numeig}); % UNCONDITIONAL MOMENTS Moments(1,1) = S'*pi_LR;%(1,:)'; %unconditional mean %Moments(2,1) = sum( (S - (S'*pi_LR)).^2.*pi_LR); %unconditional variance Moments(2,1) = sqrt(pi_LR'*((S - Moments(1,1)).^2)); %unconditional variance end %this closes the "else" on line 26


Reply With Quote