%单机无穷大系统动态过程 用隐式梯形积分法求解编程
tic
clear all
clc
%初值参数
%%%同步发电机参数
Wref=1; %参考转速
W(1)=0.98; %转子角速度,简称转速
TJ(1)=40.28; %同步电机的转子机械惯性时间常数
Xd(1)=0.1460; %d轴同步电抗
Xd1(1)=0.0608; %d轴暂态电抗
Xq(1)=0.0969; %q轴同步电抗
Td0(1)=8.96; %d轴开路暂态时间常数
DX(1)=0.1; %阻尼系数
%%%输电线及变压器参数
XT=0.0576; %变压器阻抗
RL1=0.01; %一回路输电线路电阻
XL1=0.085; %一回路输电线路电抗
Y1=0.088i; %一回路输电线路对地导纳
RL2=0.017; %二回路输电线路电阻
XL2=0.092; %二回路输电线路电抗
Y2=0.079i; %二回路输电线路对地导纳
ZXL=XT*i+((RL1+XL1*i+2/(Y1))*(RL2+XL2*i+2/(Y2)))/(RL1+XL1*i+2/(Y1)+RL2+XL2*i+2/(Y2)); %双回输电线路的pi型等值阻抗
RL=real(ZXL); %等值线路的电阻
XL=imag(ZXL); %等值线路的电抗
%%%原动机及调速器传递函数参数
Ka=20; %转速测量比较放大系数
Kr=3/5; %硬反馈放大系数
Kb=6; %软反馈放大系数
Ts=4; %接力器时间常数
Tb=2.5; %软反馈时间常数
Tw=0.5; %水锤时间常数
%%%励磁系统传递函数参数
TR=0.001; %测量惯性环节时间常数
KA=20; %惯性放大环节放大倍数(!注意励磁的a大写,与调速的a小写区别)
TA=0.1; %惯性放大环节时间常数
TF=0.02; %励磁电压负反馈惯性微分环节时间常数
KF=0.03; %励磁电压负反馈惯性微分环节放大倍数
TL=0.5; %直流励磁机传递函数,计及饱和作用的惯性环节时间常数
KL=1; %直流励磁机传递函数,计及饱和作用的惯性环节放大倍数
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
u(1)=1.05; %%发电机端电压幅值
J(1)=0.00; %%电压相角
U(1)=u(1)*cos(J(1))+u(1)*sin(J(1))*1i;%机端电压向量
Vx(1)=real(U(1)); %机端电压实部
Vy(1)=imag(U(1)); %机端电压虚部
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
V0(1)=1.0; %%末端电压(无穷大母线处的电压,一般假设为恒值)
Ix(1)=(Vx(1)*RL+Vy(1)*XL-V0(1)*RL)/(RL^2+XL^2);
Iy(1)=(V0(1)*XL-Vx(1)*XL+Vy(1)*RL)/(RL^2+XL^2);
I(1)=Ix(1)+Iy(1)*i;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ED01=U(1)+I(1)*Xq(1)*i; %%求虚构电势
D(1)=angle(ED01); %%求发电机的转子角度
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Eq1(1)=real(U(1))*cos(D(1))+imag(U(1))*sin(D(1))+Xd1(1)*(real(I(1))*sin(D(1))-imag(I(1))*cos(D(1))); %%%暂态电势
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
mid1=real(I(1))*cos(D(1))+imag(I(1))*sin(D(1)); %mid1=Iq q轴电流
mid2=real(I(1))*sin(D(1))-imag(I(1))*cos(D(1)); %mid2=Id d轴电流
Pe(1)=mid1*Eq1(1)-(Xd1(1)-Xq(1))*mid2*mid1; %电磁功率
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DW(1)=W(1); %转速
DD(1)=D(1); %功角
Pm(1)=Pe(1); %%电磁功率的初值
DPT(1)=Pm(1)+DX(1)*W(1); %%机械功率的初值
DU(1)=DPT(1); %导水翼开度
DUN(1)=DPT(1); %导水翼参考开度
DJ1(1)=0; %总反馈量
DEq1(1)=Eq1(1); %暂态电势
DV1(1)=sqrt(Vx(1)^2+Vy(1)^2);%电压中间变量v1
DV2(1)=0; %电压中间变量v2
DEfd(1)=Eq1(1)+(Xd(1)-Xd1(1))*(real(I(1))*sin(D(1))-imag(I(1))*cos(D(1)));%励磁电压
DV3(1)=(2*KL-1)*DEfd(1); %电压中间变量v3
VF0(1)=1.025; %%DV3(1)/KA+DV1(1);参考输入电压
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h=0.02; %时间步长
DT=h;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