Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

YEUNGKAWING20353855_4

function PowerIter

n=500;
A=randn(n,n);
A=(A+A')/2;

for testtime=1:5
    y0=randn(n,1);
    y0=y0/norm(y0);
    [mu,y]=Power(A,y0);
    % Store mu and y
    mu1(testtime)=mu;
    y1(:,testtime)=y;
end
% Display the results
disp('The computed eigenvalues are shown below. You will see they are almost the same.')
disp(mu1)
disp('The inner products of computed eigenvectors are shown below.');
disp('You will see some are close to 1, and some are close to -1.');
disp('This shows that the computed vectors may be in opposite direction'); 
disp('but both are the same eigenvector.')
disp(y1'*y1)

% Below is the subroutine of power iteration.     
    function [mu,y]=Power(A,y0)
        maxit=10^4;
        epsilon=1e-6;
        y=y0;
        for iter=1:maxit
            %%%%%%% 
            %Insert your lines for Power Iteration
            m^(k)=A*y^(k-1)
            y^(k)=m^(k)/abs (m^k)_2
            U^(k)=(y^(k))'*A*(y^(k)) 
            
            
            %%%%%%%
            % Check: if ||Ay^k - mu^k y^k ||_2<= epsilon, then break the
            % for loop.
            % Complete the following line
            if 
            abs (A*y^k - m*u^k y^k)_2 <= epsilon
                break;
            end
        end
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    end

end

ButterWorthLPF

x = [1 2 3 4 5 6 7 8 9 10];
y1 = [.16 .08 .04 .02 .013 .007 .004 .002 .001 .0008 ];
y2 = [.16 .07 .03 .01 .008 .003 .0008 .0003 .00007 .00002 ];

semilogy(x,y1,'-bo;y1;',x,y2,'-kx;y2;');
title('Plot title');
xlabel('X Axis');
ylabel('Y Axis');

print -dpng figure.png

Execute MATLAB/Octave Online

f_cutoff = 2000
f_sample_rate = 10000
nth_order = 2

fnorm = f_cutoff/(f_sample_rate/2); % normalized cut off freq, https://www.exstrom.com/journal/sigproc
% Low pass Butterworth filter of order N
[b1, a1] = butter(nth_order, fnorm,'low');

Execute MATLAB/Octave Online

%L = imread('images/lena3.jpg');
L = imread('images/Toronto2_F.png');
L=rgb2gray(L);
figure(1);
imshow(L);

b=256;  % block size used to look for duplicates
b1=sqrt(b); 
Nn = 5; % how many close rows to check
Nd = 15; %Threashold
Nc=26; % Truncate PCA at this length
Nt=26;

% calculate the total size of the image
n = numel(L);

b2 = sqrt(n)-sqrt(b)+1;
% calculate Nb
Nb= power((sqrt(n)-sqrt(b)+1),2);

% the matix of Nc plus the position
M=zeros(Nb,  Nc);
% temp index array
Mi = zeros(Nb, 2);
i=1;
disp('Starting PCA');
for r = 1:b2
   for c = 1:b2
       % Extract each block
      B = L(r:r+b1-1,c:c+b1-1);

      [pc, latent, explained] = pcacov(cov(double(B)));
      %[pc, latent, explained] = princomp(double(B), 'NumComponents', Nc);

      Z = pc(1:Nc);
      Mi(i,:) = [r c];
      M(i,:) = Z;      
      i = i+1;
   end
end

disp('Sorting M -> S');
%Sort M array in lexicographic order -> S
[S, index] = sortrows(M);
P= zeros(1,3);
disp('Finding Duplicates');
for i = 1:Nb
    iv = index(i);
    xi=mod(iv,b2) + 1;
    yi=ceil(iv/b2);
    j = i+1;    
    while j < Nb && abs(i - j) < Nn
        jv=index(j);
        xj=mod(jv,b2) + 1;
        yj=ceil(jv/b2);

        z=sqrt(power(xi-xj,2) + power(yi-yj,2));
        % only process those whose size is above Nd 

        if z > Nd

            idx = find(P(:,1)== xi & P(:,2)==yi, 1, 'last');
            if isempty(idx)==1
               P = [P; [xi, yi, 1]];                 
            else
               P(idx,3) = P(idx,3) + 1;
            end

            idx = find(P(:,1)== xi & P(:,2)==yi, 1, 'last');
            if isempty(idx)==1
               P = [P; [xj, yj, 1]];
            else
               P(idx,3) = P(idx,3) + 1;                  
            end            
        end                        
       j = j + 1;
    end
end

disp('Sorting findings');
rows = size(P,1);
% sort descending order
P = sortrows(P, -3);
% Mark the found blocks
disp('Creating Image');
idx = 1;
% Create a black image
RI = zeros(sqrt(n), sqrt(n));
while idx < rows && P(idx,3) > 5
    x = P(idx,1);
    y = P(idx,2);
    RI(x,y) = 1;
    idx = idx + 1;
end

figure(2);
imshow(RI);

Matlab Matrix Referencing elements

% bai tap 1 
a1=10/2\5-3+2*4
b1=3^2/4
c1=3^2^2
d1=2+round(6/9 + 3*2)/2-3
e1=2+floor(6/11)/2-3
f1=2+ceil(-6/9)-3
g1=fix(-4/9)+fix(3*(5/6))
% bai tap 2
a2=mod(36,15)
b2=rem(36,15)
c2=gcd(36,15)
d2=lcm(36,15)
% bai tap 3
a3=1 & -1
b3=13 & (-6)
c3=0<-20
d3=0<=0.2<=0.4
e3=5>4>3
f3=2>3&1
% bai tap 4
x4=[3 1 5 7 9 2 6]
a4=x4(3)
b4=x4(1:7)
c4=x4(1:end)
d4=x4(1:end-1)
e4=x4(6:-2:1)
f4=x4([1 6 2 1 1])
g4=sum(x4),min(x4),max(x4)
% bai tap 5, so sánh từng phần tử của x5 với y5, nếu đúng trả về 1, sai trả về 0 
x5=[1 5 2 8 9 0 1]
y5=[5 2 2 6 0 0 2]
a5=x5>y5 
b5=y5<x5 
c5= x5==y5 
d5 = x5<=y5
e5 = y5>=x5
f5 = x5|y5
g5 = x5&y5
h5 = x5&(-y5)
i5=(x5>y5)|(y5<x5)
j5=(x5>y5)&(y5<x5)
% bài 6
x6=[1 0 2]
y6=[0 2 2]
x6=y6
b6=x6<y6
c6= x6<y6<x6 
d6 = x6<y6<y6
e6 = x6 | (x6)
f6 = y6&(y6)
x6=y6==x6
% bài 7
x7=1:10
y7=[3 1 5 6 8 2 9 4 7 0]
a7=(x7>3)&(x7<8)
b7=x7(x7>5)
c7=y7(y7<4)
d7=x7(x7<2)|(x7>=8)
e7=y7(x7<2)|(x7>=8)
f7=x7(y7<0)
% bài 8
x8=[1 4 8]
y8 = [2 1 5]
z8=[2 7 9 7;3 1 5 6;8 1 2 5]
a8=[x8;y8]
b8=z8(:,[1 4])
c8=z8([2 3],[3 1])
d8=z8(:)
% bài 13
x13=[1 4 8]
y13 = [2 1 5]
z13=[3 1 6;5 2 7]
a13=x13+y13
b13=z13-3
% bài 14
x14=[2 7 9 7;3 1 5 6;8 1 2 5]
a14=x14'
b14=sum(x14)
c14=sum(x14')
d14=sum(x14, 2)























Newton rapshon

clc
clear
m=0.8;
i=1;
a_m=[18;28];
delta(2,1)=0;
i_matrix(:,1)=0;
a1_matrix(:,1)=0;
a2_matrix(:,1)=0;
while true
jacob=[-sind(a_m(1,1))-sind(a_m(2,1));...
      -3*sind(3*a_m(1,1))-3*sind(3*a_m(2,1));...
      -5*sind(5*a_m(1,1))-5*sind(5*a_m(2,1));...
      -7*sind(7*a_m(1,1))-7*sind(7*a_m(2,1))]
      
b_func=[2*m;0];
f_func=[cosd(a_m(1,1))+cosd(a_m(2,1));...
     3*cosd(3*a_m(1,1))+3*cosd(3*a_m(2,1));..
     5*cosd(5*a_m(1,1))+5*cosd(5*a_m(2,1));...
     7*cosd(7*a_m(1,1))+7*cosd(7*a_m(2,1))]
delta= jacob/(b_func-f_func);
a_m=acosd(abs(cosd(a_m+delta)));
i_matrix(i,1)=i;
a1_matrix(i,1)=a_m(1,1); 
a2_matrix(i,1)=a_m(2,1);
if max(abs(delta))<0.057
break
end
i=i+1;
end
display(sort(a_m));
plot=(i_matrix,a1_matrix,i_matrix,a2_matrix
a=a_m(1,1);
b=a_m(2,1); 
t=0.02;




     
     

antistr_simpliromatiki

%antistr_simpliromatiki(dna)
ArxikiAllilouxia="AGTAGCAT";
AntistrofiAllilouxia="";
SimbliromatikiAllilouxia="";
for i=1:length(ArxikiAllilouxia)
      newStr = substr (ArxikiAllilouxia,i, 1)
     fprintf("",newStr); 
     if (newStr=="A")
    SimbliromatikiAllilouxia= strcat(SimbliromatikiAllilouxia, "T")
    AntistrofiAllilouxia=strcat("T",AntistrofiAllilouxia)
     elseif(newStr=="G")
     SimbliromatikiAllilouxia= strcat(SimbliromatikiAllilouxia, "C")
     AntistrofiAllilouxia=strcat("C",AntistrofiAllilouxia)
     elseif(newStr=="C")
    SimbliromatikiAllilouxia= strcat(SimbliromatikiAllilouxia, "G")
    AntistrofiAllilouxia=strcat("G",AntistrofiAllilouxia)
     elseif(newStr=="T")
     SimbliromatikiAllilouxia= strcat(SimbliromatikiAllilouxia, "A")
     AntistrofiAllilouxia=strcat("A",AntistrofiAllilouxia)
     endif
      i=i+1
     
     fprintf("1",SimbliromatikiAllilouxia); 
  
end

Exercise-Parto

a = (1:20).^3;
b = cumsum(a);
c = cumprod(b)

% cumprod(cumsum((1:20).^3))

momanddad

L=[20 -1 -1 -1 -1 -1 0 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 -1 -1 0 0 -1 -1 0 -1 0 -1 -1 -1 -1 0 0 0 0 ;
-1 8 0 0 0 0 0 -1 0 0 0 0 -1 -1 0 0 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ;
-1 0 2 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ;
-1 0 0 2 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ;
-1 0 0 0 2 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 6 0 0 0 ;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 ;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 3 0 ;
0 0 0 0 0 0 0 -1 -1 0 0 0 0 -1 0 0 -1 0 -1 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 -1 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 -1 0 -1 0 0 0 0 0 12]; 
k=eig(L);
for i=1:length(k)
sprintf('%f',k(i,1))
end

MarketShare

function [] = demo()
    clc; clear all;
    %% Market share draft
    
    Lambdaiwant = 1.501;
    
    % Number of points
    npoints = 100;
    
    % Number of muN settings
    nmuN = 1;
    
    
    MSfast = zeros(nmuN,npoints);
    
    MSfastub = zeros(nmuN, npoints);
    MSfastlb = zeros(nmuN, npoints);
    Lambdavalues = zeros(nmuN, npoints);
    
    muNsettings = [1.1];
    
    settingnumber = 0;
    for muN=muNsettings
    
        settingnumber = settingnumber+1
    
        a = 0.5;
    
        low = 0.05;
        high = (1 + muN)*0.94;
    
        stepsize = (high - low)/(npoints - 1);
    
    
        count = 0;
    
        % Original Tmin
        Tmin = 10;
        for Lambda = low : stepsize : high
            count = count + 1
        
            [pis, iMax, jMax, Tmin] = StationaryProbabilities( muN, Lambda, a, 20);
            [lambdaslow, lambdafast] = FindArrivalRates( Lambda, iMax, jMax, muN, a, pis );
            Lambdavalues(settingnumber,count) = Lambda;
            MSfast(settingnumber,count) = lambdafast/Lambda;
    
        end;
    
    end;
end


function [ pis, iMax, jMax, T] = StationaryProbabilities( muN, Lambda, a, Tmin)
%% This script finds the stationary probabilities when both A and N announce. Without loss of generality, let \mu_A = 1 and \mu_N take a higher value
% T is the threshold that we move to attain an epsilon condition
% pis is a matrix of stationary probabilities imax X jmax. i indexes slow server A, j
% indexes fast server N.

% Direction = -1 implies muN is barely less than its value. +1 implies muN is
% barely more than its value.

if(Lambda/(1+muN) > 0.95)
    epsilon = 1e-3;
else
    epsilon = 1e-4  ;
end;

% What is the minimum I should allow T to be?
% Tmin = 20;

%Lambda = Lambda - 0.0001;
% Initialize
condition = 1;
T = Tmin-1;
% This would go into a loop
while(condition > epsilon)
    T = T+1;
    iMax = T;
    jMax = ceil(T * muN);
    % Solve Ax = b
    A = zeros((iMax+1) * (jMax+1), (iMax+1) * (jMax+1));
    b = zeros((iMax+1) * (jMax+1),1);

    % Put in the coefficients for A - one for each state (except 0,0) and one
    % for normalization
    eqcount = 0;
    for i=0:iMax
        for j=0:jMax
            % Ignore state (0,0)
            if(i==0 && j==0)
                continue;
            end;

            % Otherwise
            eqcount = eqcount + 1;
            b(eqcount) = 0;

            % Find the coefficients, which depend on the values of i and
            % j
            if(i==0)
                A(eqcount,Scalarize(i,j,jMax+1)) = Lambda + muN;
                A(eqcount,Scalarize(i+1,j,jMax+1)) = -1;
                if(j==1)
                    A(eqcount,Scalarize(0,0,jMax+1)) = -Lambda * a;
                end;
                if(j<muN*T)
                    A(eqcount,Scalarize(i,j+1,jMax+1)) = -muN;
                end;
                continue;
            end;

            if(j==0)
                A(eqcount,Scalarize(i,j,jMax+1)) = Lambda + 1;
                A(eqcount,Scalarize(i,j+1,jMax+1)) = -muN;
                if(i==1)
                    A(eqcount,Scalarize(0,0,jMax+1)) = -Lambda *(1-a);
                end;
                if(i<T)
                    A(eqcount,Scalarize(i+1,j,jMax+1)) = -1;
                end;            
                continue;
            end;

            if(i==T && j==muN*T)
                A(eqcount,Scalarize(i,j,jMax+1)) = 1 + muN;
                A(eqcount,Scalarize(i,j-1,jMax+1)) = -Lambda;
                A(eqcount,Scalarize(i-1,j,jMax+1)) = -Lambda;
                continue;
            end;

            if(j==muN*T)
                A(eqcount,Scalarize(i,j,jMax+1)) = Lambda + muN + 1;
                A(eqcount,Scalarize(i+1,j,jMax+1)) = -1;
                A(eqcount,Scalarize(i-1,j,jMax+1)) = -Lambda;
                
                if(j-1 == muN * i)
                    A(eqcount,Scalarize(i,j-1,jMax+1)) = -Lambda*a;
                elseif(j-1 < muN * i)
                    A(eqcount,Scalarize(i,j-1,jMax+1)) = -Lambda;
                end;
                
                %{
                if(direction == -1)
                    if(j-1 <= muN*i)
                        A(eqcount,Scalarize(i,j-1,jMax+1)) = -Lambda;
                    end;
                elseif(direction == 1)
                    if(j-1 < muN*i)
                        A(eqcount,Scalarize(i,j-1,jMax+1)) = -Lambda;
                    end;
                end;
               %}
            
                continue;
            end;

            if(i==T)
                A(eqcount,Scalarize(i,j,jMax+1)) = Lambda + muN + 1;
                A(eqcount,Scalarize(i,j+1,jMax+1)) = -muN;
                A(eqcount,Scalarize(i,j-1,jMax+1)) = -Lambda;
                
                if(j == muN * (i-1))
                    A(eqcount,Scalarize(i-1,j,jMax+1)) = -Lambda*(1-a);
                elseif(j > muN * (i-1))
                    A(eqcount,Scalarize(i-1,j,jMax+1)) = -Lambda;
                end;
                
                %{
                if(direction == -1)
                    if(j >= muN*(i-1))
                        A(eqcount,Scalarize(i-1,j,jMax+1)) = -Lambda;
                    end;
                elseif(direction == 1)
                    if(j > muN*(i-1))
                        A(eqcount,Scalarize(i-1,j,jMax+1)) = -Lambda;
                    end;
                end;
                %}
                continue;
            end;

            % Otherwise, it is a generic state (i,j)
            A(eqcount,Scalarize(i,j,jMax+1)) = Lambda + muN + 1;
            A(eqcount,Scalarize(i+1,j,jMax+1)) = -1;
            A(eqcount,Scalarize(i,j+1,jMax+1)) = -muN;
            
            if(j > muN*(i-1))
                    A(eqcount,Scalarize(i-1,j,jMax+1)) = -Lambda;
            elseif (j == muN*(i-1))
                    A(eqcount,Scalarize(i-1,j,jMax+1)) = -(1-a) * Lambda;
            end;
            
            if(j-1 < muN*i)
                    A(eqcount,Scalarize(i,j-1,jMax+1)) = -Lambda; 
            elseif(j-1 == muN * i)
                    A(eqcount,Scalarize(i,j-1,jMax+1)) = -a * Lambda;
            end;        
            
            %{
            if(direction==-1)
                if(j >= muN*(i-1))
                    A(eqcount,Scalarize(i-1,j,jMax+1)) = -Lambda;
                end;
                if(j-1 < muN*i)
                    A(eqcount,Scalarize(i,j-1,jMax+1)) = -Lambda; 
                end;        
            elseif(direction==1)
                if(j > muN*(i-1))
                    A(eqcount,Scalarize(i-1,j,jMax+1)) = -Lambda;
                end;
                if(j-1 <= muN*i)
                    A(eqcount,Scalarize(i,j-1,jMax+1)) = -Lambda; 
                end; 
            end;
            %}
        end;
    end;

    % Add the normalization equation
    eqcount = eqcount + 1;
    A(eqcount,:) = 1;
    b(eqcount) = 1;

    x = A\b;

    % Squarify
    pis = vec2mat(x,jMax+1);

    condition = sum(pis(iMax+1,:))+sum(pis(:,jMax+1));
    %condition = pis(iMax+1, jMax+1);
end;
%T
end

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.