-
Notifications
You must be signed in to change notification settings - Fork 3
/
lfcomp3.m
78 lines (68 loc) · 1.65 KB
/
lfcomp3.m
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
% LFCOMP Conventional Newton-Raphson method for load Flow analysis
% LFCOMP provides load flow results.
%
%lfcntrup;
n=length(x);
v=zeros(n,1);
OldFigNumber=watchon;
param;
k_temp=no_gen+no_pv-1;
for i=1:k_temp
paramx(i)=param(i);
end
for i=1:no_pq
ii=k_temp+i;
jj=k_temp+1+2*(i-1);
paramx(ii)=param(jj);
paramx(ii+no_pq)=param(jj+1);
end
param=paramx';
param;
ConvergenceFlag=0;
for j=1:round(MaxIterations/ReportCycle)
OldFigNumber=watchon;
t0=clock;
for i=1:ReportCycle
x0=x;
[f,J]=eval([CurrentSystem,'(data,x,[0;param],v)']);
delta_x=-sparse(J(2:n+1,1:n))\f(2:n+1);
x=x0+delta_x;
end
AbsError=max(abs(x-x0));
if x0==0
RelError='NA';
else
RelError=AbsError/max(abs(x0));
end
lfsetsta;
% set LF control control errors
%set(AbsErrorDisp,'String',num2str(AbsError,3));
%if isstr(RelError)
%set(RelErrorDisp,'String',RelError);
%else
%set(RelErrorDisp,'String',num2str(RelError,3));
%end
%set(NumIterations,'String',num2str(j*ReportCycle));
% set(IterationTime,'String',num2str(etime(clock,t0)/ReportCycle));
if ((AbsError<=LFAbsTol*0.001) & ((~isstr(RelError)) & ...
(RelError<=LFRelTol*0.01) | isstr(RelError)))
ConvergenceFlag=1;
break;
end
end
if ConvergenceFlag==0
'NR Failed to Converge'
break;
end
for i=1:k_temp
paramx(i)=param(i);
end
for i=1:no_pq
ii=k_temp+i;
jj=k_temp+1+2*(i-1);
paramx(jj)=param(ii);
paramx(jj+1)=param(ii+no_pq);
end
param=paramx;
param;
watchoff;