Here is my another m file. When I run it, I get this error:
Error in dfig (line 78)
Ps(i)= 1.5*(Rs*ids.^2 + Rs*iqs.^2 + ws*Fs.*iqs);
% DFIG parameters --> rotor parameters referred to the stator side
f = 50;
Ps = 2e6;
n = 1500;
Vs = 690;
Is = 1790;
%Tem = 12732;
p = 2;
u = 1/3;
Vr = 2070;
smax = 1/3;
Vr_stator = Vr*smax*u;
Rs = 2.6e-3;
Lsi = 0.087e-3;
Lm = 2.5e-3;
Rr = 2.9e-3;
Ls = Lm + Lsi;
Lr = Lm + Lsi;
Vbus = Vr_stator*sqrt(2);
sigma = 1 - Lm^2 /(Ls*Lr);
Vs = 690*sqrt(2/3);
ws = f*2*pi;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Maximum and minimum speeds
wt_nom = 18;
wt_min = 9;
% Gerabox ratio
N = 100;
% Torque and speed arrays
wt = [0.9425,0.9425,0.9425,0.9424,1.0476,1.1429,1.2381,1.3333,1.4286,...
1.5235,1.6190,1.7143,1.8095,1.8850,1.8850,1.8850,1.8850,1.8850,...
1.8850,1.8850,1.8850];
Torque = -1e6*[0.0501,0.1164,0.1925,0.2696,0.3262,0.3883,0.4557,0.5285,...
0.6067,0.6902,0.7792,0.8736,0.9733,1.0894,1.2474,1.2745,...
1.2745,1.2745,1.2745,1.2745,1.2745];
i = 0;
Temm = Torque/N;
wmm = wt*(60/2/pi)*N;
sss = (1500 - wmm)/1500;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Qs = 0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Ref_Qs_ = 0*ones(size(sss));
i = 0;
for ss = sss,
i=i+1;
for Tem= Temm(i), i = i+1;
Ref_Qs = Ref_Qs_(i);
Wm = ws*(1-ss);
s(i) = ss;
end
A = ws*ws*Lm*Lm;
B = 4*Rs^2*Tem*ws/3 - ((Vs)^2);
C = 4*Rs^2/(9*Lm^2)*((Ref_Qs.^2)/(ws^2)*(Tem.^2)/(p^2));
X1 = ( -B + sqrt(B.^2-4*A.*C))./(2*A);
X2 = (-B-sqrt(B.^2-4*A.*C))./(2*A);
Fs = Lm*sqrt(X1);
Fs(i) = Fs;
% stator currents
for ids = 2*Ref_Qs./(3*ws*Fs), i=i+1;
for iqs = 2*Tem./(3*p*Fs), i=i+1;
end
end
Is(i) = sqrt(ids.^2+ iqs.^2);
% stator voltages
for uds = Rs*ids,i = i+1;
for uqs = Rs*iqs + ws*Fs,i=i+1;
end
end
Us(i) = sqrt(uds.^2 + uqs.^2);
% satator power
Ps(i)= 1.5*(Rs*ids.^2 + Rs*iqs.^2 + ws*Fs.*iqs);
Qs(i) = Ref_Qs, i=i+1;
Mod_Ss = sqrt(Ps.^2 + Qs.^2);
% Rotor currents
for idr = -Ls*ids/Lm + Fs/Lm, i = i+1;
for iqr = -Ls*iqs/Lm, i = i+1;
end
end
Ir(i)=sqrt(idr.^2 + iqr.^2);
% wr
wr = ws*ss;
% rotor voltages
udr = Rr*idr - Lr*wr.*iqr - Lm*wr.*iqs;
uqr = Rr*iqr + Lr*wr.*idr + Lm*wr.*ids;
Vr(i) = sqrt(udr^2 + uqr^2);
% Rotor power
Pr(i) = 1.5*(udr.*idr + uqr.*iqr);
Qr(i) = 1.5*(uqr.*idr - udr.*iqr);
Mod_Sr = sqrt(Pr.^2 + Qr.^2);
% stator flux
Fsd = Ls*ids + Lm*idr;
Fsq = Ls*iqs + Lm*iqr;
Fs(i) = sqrt(Fsd^2 +Fsq^2);
% rotor flux
Frd = Lr*idr + Lm*ids;
Frq = Lr*iqr + Lm*iqs;
Fr(i) = sqrt(Frd.^2 + Frq.^2);
% mechanical power
Pmec(i) = Tem*Wm/p;
% efficiancy
if Pmec(i) >= 0
R(i) = Pmec(i) / (Ps(i) + Pr(i)); % motor mode
else
R(i) = (Ps(i) + Pr(i))/Pmec(i); % motor mode
end
end
figure(1)
subplot(3,3,1)
hold on
plot(wmm,Temm,'r',wmm,Temm,'or','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Tem (NM)','fontsize',14);
xlim([700,2000]);
subplot(3,3,2)
hold on
plot(wmm,Ps + Pr,'r',wmm,Ps + Pr, 'or','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Pt (W)','fontsize',14);
xlim([700,2000]);
subplot(3,3,3)
hold on
plot(wmm,Pr,'r',wmm,Pr, 'ogr','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Pr (W)','fontsize',14);
xlim([700,2000]);
subplot(3,3,3)
hold on
plot(wmm,Ps,'r',wmm,Ps, 'ogr','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Ps & Pr(W)','fontsize',14);
xlim([700,2000]);
subplot(3,3,4)
hold on
plot(wmm,Is,'r',wmm,Is, 'or','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Is (A)','fontsize',14);
xlim([700,2000]);
subplot(3,3,5)
hold on
plot(wmm,Ir,'r',wmm,Ir, 'or','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Ir (A)','fontsize',14);
xlim([700,2000]);
subplot(3,3,6)
hold on
plot(wmm,Vr,'r',wmm,Vr, 'or','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Vr & Vs (V)','fontsize',14);
xlim([700,2000]);
subplot(3,3,7)
hold on
plot(wmm,Qs,'r',wmm,Qs, 'or','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Qs (VAR)','fontsize',14);
xlim([700,2000]);
subplot(3,3,8)
hold on
plot(wmm,Qr,'r',wmm,Qr, 'or','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Qr (VAR)','fontsize',14);
xlim([700,2000]);
subplot(3,3,9)
hold on
plot(wmm,R,'r',wmm,R, 'or','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Efficiency (pu)','fontsize',14);
xlim([700,2000]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% idr = 0
i=0;
for ss = sss,
i = i + 1;
Tem = Temm(i);
Wm = ws*(1 - ss);
s(i) = ss;
A = ws^2*Lm^2 + (Rs*Lm/Ls)^2;
B = 4*Rs*Tem*ws/3/p -((Vs)^2);
C = 4*Rs^2*Tem^2 / (9*p^2*Lm^2);
X1 = (-B + sqrt(B.^2 - 4*A.*C))./(2*A);
X2 = (-B - sqrt(B.^2 - 4*A.*C))./(2*A);
ims = sqrt(X1);
ims(i) = ims;
Fs = ims*Lm;
% rotor currents
idr = 0;
iqr = -2*Tem*Ls./(3*p*Lm*Fs);
Ir(i) = sqrt(idr^2 + iqr^2);
% stator currents
ids = Fs/Ls;
iqs = -iqr*Lm/Ls;
Is(i) = sqrt(ids^2 + iqs^2);
% Stato vlotages
uds = Rs*ids;
uqs = Rs*iqs;
Us(i) = sqrt(uds^2 + uqs^2);
% stator powers
Ps(i) = 1.5*(Rs*ids.^2 + rs*iqs.^2 + ws*Fs.*iqs);
Qs(i) = 1.5*(uqs.*ids - uds.*iqs);
Mod_ss =sqrt(Ps.^2 + Qs.^2);
% wr
wr = ws*ss;
% rotor voltages
udr = Rr*idr - Lr*wr.*iqr - Lm*wr.*iqs;
uqr = Rr*iqr + Lr*wr.*idr + Lm*wr.*ids;
Vr(i) = sqrt(udr^2 + uqr^2);
%rotor powers
Pr(i) = 1.5*(udr.*idr + uqr.*iqr);
Qr(i) = 1.5*(uqr.*idr - udr.*iqr);
Mod_Sr = sqrt(Pr.^2 + Qr.^2);
% stator flux
Fsd = Ls*ids + Lm*idr;
Fsq = Ls*iqs + Lm*iqr;
Fs(i)= sqrt(Fsd^2 + Fsq^2);
% rotor flux
Frd = Lr*idr + Lm*ids;
Frq = Lr*iqr + Lm*iqs;
Fr(i)= sqrt(Frd^2 + Frq^2);
% Mechanial power
Pmec(i) = Tem*Wm/p;
% efficiancy
if Pmec(i) >= 0
R(i) = Pmec(i) / (Ps(i) + Pr(i)); % Motor Mode
else
R(i) = (Ps(i) + Pr(i))/Pmec(i); % Generator Mode
end
end
figure(1)
subplot(3,3,1)
hold on
plot(wmm,Temm,'g',wmm,Temm,'og','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Tem (Nm)','fontsize',14);
grid
xlim([700,2000]);
subplot(3,3,2)
title('Red: Qs = 0, Green: idr = 0','fontsize',12)
hold on
plot(wmm,Pr,'g',wmm,Ps+Pr,'og','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Pt (W)','fontsize',14);
grid
xlim([700,2000]);
subplot(3,3,3)
hold on
plot(wmm,Pr,'g',wmm,Pr,'og','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Pr (W)','fontsize',14);
xlim([700,2000]);
subplot(3,3,3)
hold on
plot(wmm,Ps,'g',wmm,Ps,'*g','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Ps & Pr (W)','fontsize',14);
grid
xlim([700,2000]);
subplot(3,3,4)
hold on
plot(wmm,Is,'g',wmm,Is,'og','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Is (A)','fontsize',14);
grid
xlim([700,2000]);
subplot(3,3,5)
hold on
plot(wmm,Ir,'g',wmm,Ir,'og','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Ir (A)','fontsize',14);
grid
xlim([700,2000]);
subplot(3,3,6)
hold on
plot(wmm,Vr,'g',wmm,Vr,'og',wmm,Us,'g',wmm,Us,'og','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Vr & Vs (V)','fontsize',14);
grid
xlim([700,2000]);
subplot(3,3,7)
hold on
plot(wmm,Qs,'g',wmm,Qs,'og','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Qs (VAR)','fontsize',14);
grid
xlim([700,2000]);
subplot(3,3,8)
hold on
plot(wmm,Qr,'g',wmm,Qr,'og','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Qr (VAR)','fontsize',14);
grid
xlim([700,2000]);
subplot(3,3,9)
hold on
plot(wmm,R,'g',wmm,R,'og','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Efficiency (pu)','fontsize',14);
grid
xlim([700,2000]);