Advertisement
Ailili1997

Lab Code

Jun 12th, 2020
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. clear all
  2. clc
  3. %Initialization
  4. V=[];
  5. V(1,:)=[1,1,1];
  6. w=[];
  7. w(1)=1;
  8. Ploss(1) = 0;
  9. %Grid Parameters
  10. D_w = 100;
  11. D_v = 20;
  12. w0=1; %nominal value
  13. V0 = 1;
  14. Vbase= 381;
  15. Sbase= 10000;
  16. fbase = 50;
  17. Ibase = Sbase/(sqrt(3)*Vbase);
  18. Zbase = (sqrt(3)*Vbase^2)/Sbase;
  19. P_4 = 1;
  20. P_5 = 1;
  21. l_1=[0.01:0.01:0.05] ;
  22. % r_1=[0.01:0.01:0.05];
  23. %Algorithm
  24. for a =1:5
  25. % r1=r_1(a);
  26. r1=0.0103 ;
  27. l1=l_1(a);
  28. for i=2:10000000000
  29. %Y-Matrix
  30. [Y_BUS Z_12 Z_23] = Y_bus(w(i-1),r1,l1);
  31.  
  32.  
  33. %All Buses are drop Buses, Calculate PGk,QGk for 3 bus system:
  34. for n =1:3%n stands for bus index; i denotes number of iterartion
  35. Pg(i,n) = D_w*(w0 - w(i-1)); % P at Generator[1 2 3]
  36. Qg(i,n) = D_v*(V0 - abs(V(i-1,n))); % Q at Generator[1 2 3] %行数代表循环的index列数代表busindex
  37. end
  38. %Bus 1&3 contains load:add the load
  39.  
  40. Pb(i,:) = -[P_4 0 P_5] + Pg(i,:); % P injected at Bus[1 2 3]
  41. Qb(i,:) = Qg(i,:); % Q injected at Bus[1 2 3]
  42.  
  43. % %Calculate Vk(i+1)using Pb,Qb, directly come from book fomular
  44.  
  45. V(i,1)= (1/Y_BUS(1,1))*((Pb(i,1)-(Qb(i,1)*j))/conj(V(i-1,1))-Y_BUS(1,2)*V(i-1,2)-Y_BUS(1,3)*V(i-1,3)); %Voltage at Bus 1
  46. V(i,2)= (1/Y_BUS(2,2))*((Pb(i,2)-(Qb(i,2)*j))/conj(V(i-1,2))-Y_BUS(2,1)*V(i,1)-Y_BUS(2,3)*V(i-1,3)); %Voltage at Bus 2
  47. V(i,3)= (1/Y_BUS(3,3))*((Pb(i,3)-(Qb(i,3)*j))/conj(V(i-1,3))-Y_BUS(3,1)*V(i,1)-Y_BUS(3,2)*V(i,2)); %Voltage at Bus 3
  48. %
  49. % %Calculate power loss in the system
  50. %
  51. I12(i) = (V(i,1)-V(i,2))*(-Y_BUS(1,2)); %Current from Bus1 to Bus2
  52. I23(i) = (V(i,2)-V(i,3))*(-Y_BUS(2,3)); %Current from Bus2 to Bus3
  53. %
  54. Ploss(i) = ((abs(I12(i))^2)*(real(Z_12)))+((abs(I23(i))^2)*(real(Z_23)));
  55. %
  56. w(i) = w0-((P_4 + P_5 + Ploss(i))/(3*D_w));
  57. %convert pu
  58. Vbus= [abs(V(i,1)*Vbase), abs(V(i,2)*Vbase), abs(V(i,3)*Vbase)];
  59. Vbusangle = [angle(V(i,1))*(180/pi), angle(V(i,2))*(180/pi), angle(V(i,3))*(180/pi)];
  60. I = [abs(I12(i))*Ibase, abs(I23(i))*Ibase];
  61. Iangle = [angle(I12(i))*(180/pi), angle(I23(i))*(180/pi)];
  62. PG = [Pg(i,1)*Sbase, Pg(i,2)*Sbase, Pg(i,3)*Sbase];
  63. QG= [Qg(i,1)*Sbase, Qg(i,2)*Sbase, Qg(i,3)*Sbase];
  64. f= (w(i)*fbase);
  65.  
  66. %stopping condition.
  67. if norm(V(i,:)-V(i-1,:))<1e-9 && norm(w(i)-w(i-1))<1e-9
  68.  
  69. break;
  70.  
  71. end
  72.  
  73. end
  74.  
  75. VBus(a,:)= Vbus;
  76. PG_chnageload(a,:)= PG;
  77. QG_chnageload(a,:)=QG;
  78. f_chnageload(a,:)=f;
  79. end
  80.  
  81.  
  82. figure(1)
  83. plot(l_1,VBus(:,1),'-*')
  84. hold on
  85. plot(l_1,VBus(:,2),'-*')
  86. hold on
  87. plot(l_1,VBus(:,3),'-*')
  88. xlabel('Ll1(p.u.)') % x-axis label
  89. ylabel('Voltage (V)')
  90. title('The voltage at each bus')
  91. legend('Bus1','Bus2','Bus3','location','northwest')
  92.  
  93. figure(2)
  94. plot(l_1, QG_chnageload(:,1),'-*')
  95. hold on
  96. plot(l_1, QG_chnageload(:,2),'-*')
  97. hold on
  98. plot(l_1, QG_chnageload(:,3),'-*')
  99. xlabel('Ll1(p.u.)')
  100. ylabel('Reactive Power (Var)')
  101. title('The reactive power of each genrator')
  102. legend('G1','G2','G3','location','northwest')
  103. %
  104. figure(3)
  105. plot(l_1, PG_chnageload(:,1),'-*')
  106. hold on
  107. plot(l_1, PG_chnageload(:,2),'-*')
  108. hold on
  109. plot(l_1, PG_chnageload(:,3),'-*')
  110. xlabel('Ll1(p.u.)')
  111. ylabel('Active Power (W)')
  112. title('The active power of each generator')
  113. legend('G1','G2','G3','location','northwest')
  114. %
  115. % %
  116. figure(4)
  117. plot(l_1, f_chnageload,'-*')
  118.  
  119. xlabel('Ll1(p.u.)') % x-axis label
  120. ylabel('frequency (Hz)')
  121. title('The frequency of the microgrid')
  122. legend('frequency f')
  123.  
  124. function [Y_BUS,Z_12,Z_23] = Y_bus(w,r1,l1)
  125.  
  126. Z_12=r1+1j*w*l1;
  127. Z_23=0.0358+1j*w*0.0262;
  128. Y11=inv(Z_12);
  129. Y12=-inv(Z_12);
  130. Y13=0;
  131. Y21=-inv(Z_12);
  132. Y22=inv(Z_12)+inv(Z_23);
  133. Y23=-inv(Z_23);
  134. Y31=0;
  135. Y32=-inv(Z_23);
  136. Y33=inv(Z_23);
  137. Y_BUS=[Y11 Y12 Y13;Y21 Y22 Y23;Y31 Y32 Y33];
  138.  
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement