File: gk.m

package info (click to toggle)
julia 0.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 17,868 kB
  • ctags: 13,696
  • sloc: ansic: 102,603; lisp: 86,819; sh: 12,179; cpp: 8,793; makefile: 3,069; ruby: 1,594; python: 936; pascal: 697; xml: 532; java: 510; f90: 403; asm: 102; perl: 77; sql: 6
file content (163 lines) | stat: -rw-r--r-- 2,856 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
function []=gk(n,myeps)
%clear
format longEng

%A = skewdec(n,n);
%r=max(A);
%s=max(r);
%A=A/s
A=myunifskew(n);
A;

[f,g]=size(myeps);
for KK=1:g
  eps = myeps(KK);
  %xlswrite('output.xls', A,'skew-symmetric-matrix A')
  e=ones(n,1);
  X=zeros(n,1);
  U=zeros(n,1);
  p=e/n;
  t=0;
  %tm=U/t
  stop=0;
  iter=0;
  tic
    while(stop~=1)
      t=t+1;
      iter=t;
      %iteration number
      
      if rem(iter, 100) == 0
        disp(iter)
      end
      
      iter ;
      %cumsum = zeros(n,1);
      for i=1:n
        cumsum(i)=sum(p(1:i));
      end
      %zi=rand(n,1);
      con=0;
      marker=rand;
      k=1;
      %while con~=1
      for i=2:n
        if cumsum(i-1)<=marker && marker<=cumsum(i)
          k=i;
          break;
          %con=1;
        end
      end
      %end
      
      X(k)=X(k)+1;
      for i=1:n
        U(i)=U(i)+A(i,k);
      end
      
      s= (sum(p(1:n).*exp((eps/2)*A(1:n,k))));
      for i=1:n
        p(i)=(p(i)*exp((eps/2)*A(i,k))) / s;
      end
      p;
      %FID=fopen('output.txt', 'a');
      %C=fwrite(FID,p);
      %fclose(FID);
      u=U/t;
      if u<=eps*e
        stop=1;
        x=X/t;
      end
      
      %disp('hello')
      
    end
    iter;
    x;
  toc
  time(KK)=toc;
  iteration(KK) = iter;
  etx=sum(x)
  AX=A*X;
  error=abs(AX)-abs(U);
  error;
  sum(error)
  
  if A*x <= eps*e
    disp(' Ax <= eps*e  ')
  end
  if error<10^-8
    
    disp('Assertion condition is satisfied i.e. AX-U<10^-8')
    
  else
    disp('Error:  AX-U<10^-8 not satisfied ')
  end
  
  disp('Time for');
  disp(eps);
  disp('is');
  disp(time(KK));
  disp('Number of iteration is ');
  disp(iteration(KK));
end

disp('Epsilon vector is ');
disp(myeps);
disp('time vector is');
disp(time);
disp('Iteration Vector is');
disp(iteration);

out = [myeps; time; iteration];
disp('Epsilon-Time-Iteration tradeoff');
disp(out);

%save outputallvar.mat
%save outputdat.dat A -ASCII 
%xlswrite('outputxls.xls', out,'eps-time-iterations GK')

%{
xlswrite('output.xls', p,'Probability p')
xlswrite('output.xls', b,'Stp crt Udivt')
xlswrite('output.xls', x,'Opt sol x')
xlswrite('output.xls', time,'Time Taken')
xlswrite('output.xls', iter,'no of iteration')
xlswrite('output.xls',error ,'Error')
%}

function [a]=myunifskew(n)
%a=rand(n)
%{
for i=1:n
   a(i,i)=0;
end
%}

a=zeros(n);

disp('a(i,j) initialized with zeros');

for i=1:n
    for j=1:i-1
        temp=rand;
        if (temp < 0.5 )
         a(i,j)= rand;
         a(j,i)= -a(i,j);
        else
         a(j,i)= rand;
         a(i,j)= -a(j,i);
        end
    
    end
    if rem(i,1000) == 0
        disp(i)
    end
end

%{
if a == -a'
    display('Skew symmetric MATRIX CREATED');
end

%}