Author Topic: Need help in m file [ Solved ]  (Read 2848 times)

0 Members and 1 Guest are viewing this topic.

Offline abrarbaigTopic starter

  • Contributor
  • Posts: 30
  • Country: sa
Need help in m file [ Solved ]
« on: March 03, 2018, 06:07:16 pm »
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);
Code: [Select]
% 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]);
« Last Edit: March 04, 2018, 10:52:21 am by abrarbaig »
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11585
  • Country: us
    • Personal site
Re: Need help in m file
« Reply #1 on: March 03, 2018, 06:20:19 pm »
Ps is declared as a scalar value earlier, and you try to use it as an array.

Although Matlab does not seem to care if you do stuff like that.
« Last Edit: March 03, 2018, 06:22:08 pm by ataradov »
Alex
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11585
  • Country: us
    • Personal site
Re: Need help in m file
« Reply #2 on: March 03, 2018, 06:35:26 pm »
yes, if you manually evaluate the right side, it evaluates to a two-value vector. And Ps is a single value.
Code: [Select]
In an assignment  A(:) = B, the number of elements in A and B must be the same.

Error in untitled (line 78)
Ps(i)= 1.5*(Rs*ids.^2 + Rs*iqs.^2 + ws*Fs.*iqs);
 
>> 1.5*(Rs*ids.^2 + Rs*iqs.^2 + ws*Fs.*iqs)

ans =

   -78.6630748177035e+003   -78.6630748177035e+003
Alex
 

Offline ahbushnell

  • Frequent Contributor
  • **
  • Posts: 745
  • Country: us
Re: Need help in m file
« Reply #3 on: March 03, 2018, 09:47:47 pm »
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);

I think you need period after the second iqs at the end of the equation.
 

Offline abrarbaigTopic starter

  • Contributor
  • Posts: 30
  • Country: sa
Re: Need help in m file
« Reply #4 on: March 04, 2018, 10:24:17 am »
Hi. Thanks for everyone who has participated and gave your inputs. I have fixed the code. Now its working error free. Just need some fine tuning. It should be done soon.
 

Offline fathi

  • Newbie
  • Posts: 2
  • Country: tn
Re: Need help in m file [ Solved ]
« Reply #5 on: May 10, 2018, 05:50:59 pm »
for me it's the same
did you find the solution
how the programm will be??
 

Offline mbless

  • Regular Contributor
  • *
  • Posts: 227
  • Country: 00
Re: Need help in m file [ Solved ]
« Reply #6 on: May 10, 2018, 06:06:05 pm »
for me it's the same
did you find the solution
how the programm will be??

What's the error, and what's your code?

The above error was because OP was assigning a 1x2 matrix to a 1x1 matrix.
 

Offline fathi

  • Newbie
  • Posts: 2
  • Country: tn
Re: Need help in m file [ Solved ]
« Reply #7 on: May 10, 2018, 06:13:20 pm »
 This is my code

%  %
clear all   
% difg parametrs -> Rotor parameters refered to the stator side
 

f = 50;                        % Stator frequency (Hz)
Ps = 2e6;                      % rated stator power (W)
n = 1500;                      % Ratede rotational speed (rev/min)
Vs = 690;                      % Rated voltage stator (V)
Is = 1760;                     % Rated stator current (A)
Tem = 12732;                   % Rated torque (N.m)

p = 2;                         % Pole pair
u =1/3;                        % Stator/rotor turns ratio
Vr = 2070;                     % Rated rotor voltage (non-reached)(V)
smax = 1/3;                    % Maximum slip
Vr_stator = (Vr*smax)*u;       % Rated rotor voltage referred to stator (V)
Rs = 2.6e-3;                   % Stator resistance (ohm)
Lsi =  0.087e-3;               % Leakage inductance (stator & rotor) (H)
Lm = 2.5e-3;                   % magnetizing inductance (H)
Rr = 2.9e-3;                   % Rotor resistance referred to stator (ohm)
Ls = Lm + Lsi;                 % Stator induction (H)
Lr = Lm + Lsi;                 % Rotor induction (H)
Vbus = Vr_stator*sqrt(2);      % DC de bus voltage referred to stator (V)
sigma = 1-Lm^2/(Ls*Lr);        %

Vs=690*sqrt(2/3);
ws=f*2*pi;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
% Max and minimum speeds de 2.4MW

wt_nom=18;
wt_min=9;

%Gearbox ratio

N=100;

% Torque and speed arrays (inputs)

wt=[0.9425,0.9425,0.9425,0.9425,1.0476,1.1429,1.2381,1.3333,1.4286,...
    1.5238,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,06902,0.7792,0.8736,0,9733,1.0894,1.2474,1.2745,1.2745,...
        1.2745,1.2745,1.2745,1.2745];
   
Temm=Torque/N;                   % Convert to machine side
wmm=wt*(60/2/pi)*N;              % Convert to machine side (in rpm)
sss=(1500-wmm)/1500;             % slip

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%       Qs=0         %%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Ref_Qs_ =0*ones(size(sss));

i=0;
for ss=sss,
    i=i+1;
   
    Tem= Temm(i);
    Ref_Qs=Ref_Qs_(i);
   
    Wm=ws*(1-ss);
    s(i)=ss;
   
      A=ws*ws*Lm*Lm;
      B=4*Rs*Tem*ws/3-((Vs)^2);
      C=4*Rs*Rs/(9*Lm*Lm)*((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
      ids =2*Ref_Qs./(3*ws*Fs);
      iqs=2*Tem./(3*p*Fs);
      Is(i)=sqrt(ids^2+ids^2);
     
      % Stator voltages
      uds=Rs*ids;
      uqs=Rs*iqs+ws*Fs;
      Us(i)=sqrt(uds^2+uqs^2);
     
      % Stator power
      Ps(i)=1.5*(Rs*ids.^2+Rs*iqs.^2+ws*Fs.*iqs);
      Qs(i)=Ref_Qs;
      Mod_Ss=sqrt(Ps.^2+Qs.^2);
     
      % Rotor currents
      idr=Ls*ids/Lm+Fs/Lm;
      iqr=Ls*iqs/Lm;
      Ir(i)=sqrt(idr^2+iqr^2);
     
      %wr
      wr=ws*ss;
     
      % Rotor voltage;
      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*Fsd+Fsq*Fsq);
     
      % Rotor flux
      Frd=Lr*idr+Lm*ids;
      Frq=Lr*iqr+Lm*iqs;
      Fr(i)=sqrt(Frd*Frd+Frq*Frq);
     
      % Mecanical power
      Pmec(i)=Tem*Wm/p;
     
      % Efficiency
      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,'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 (Nm)','fontsize',14);
xlim([700 ,2000]);

subplot(3,3,3)
hold on
plot(wmm,Pr,'r',wmm,Pr,'or','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,Pr,'or','linewidth',1.5); 
xlim([700 ,2000]);

subplot(3,3,4)
hold on
plot(wmm,Is,'r',wmm,Ir,'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',wmm,Us,'r',wmm,Us,'or','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Vr (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 (A)','fontsize',14);
xlim([700 ,2000]);

subplot(3,3,8)
hold on
plot(wmm,Qr,'r',wmm,R,'or','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Qr (A)','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);
    Ref_Qs=Ref_Qs_(i);
   
    Wm=ws*(1-ss);
    s(i)=ss;
   
      A=ws*ws*Lm*Lm + (Rs*Lm/Ls)^2;
      B=4*Rs*Tem*ws/3/p-((Vs)^2);
      C=4*Rs*Rs*Tem*Tem/(9*p*p*Lm*Lm);
      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+ids^2);
     
      % Stator voltages
      uds=Rs*ids;
      uqs=Rs*iqs+ws*Fs;
      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 currents
      idr=0;
      iqr=2*Tem*Ls./(3*p*Lm*Fs);
      Ir(i)=sqrt(idr^2+iqr^2);
     
     
     
      % Rotor voltage;
      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*Fsd+Fsq*Fsq);
     
      % Rotor flux
      Frd=Lr*idr+Lm*ids;
      Frq=Lr*iqr+Lm*iqs;
      Fr(i)=sqrt(Frd*Frd+Frq*Frq);
     
      % Mecanical power
      Pmec(i)=Tem*Wm/p;
     
      % Efficency
      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);
xlim([700 ,2000]);

subplot(3,3,2)
title('Red: Qs=0, Gree: idr=0','fontsize',12)
hold on
plot(wmm,Ps+Pr,'g',wmm,Ps+Pr,'og','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Pt (Nm)','fontsize',14);
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,Pr,'og','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Pr & Ps (W)','fontsize',14);
xlim([700 ,2000]);

subplot(3,3,4)
hold on
plot(wmm,Is,'g',wmm,Ir,'og','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,'g',wmm,Ir,'og','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,'g',wmm,Vr,'or',wmm,Us,'r',wmm,Us,'og','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Vr (V)','fontsize',14);
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 (A)','fontsize',14);
xlim([700 ,2000]);

subplot(3,3,8)
hold on
plot(wmm,Qr,'g',wmm,R,'og','linewidth',1.5);
xlabel('n (rpm)','fontsize',14);
ylabel('Qr (A)','fontsize',14);
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);
xlim([700 ,2000]);



 don't know how th correct it
I
 

Offline mbless

  • Regular Contributor
  • *
  • Posts: 227
  • Country: 00
Re: Need help in m file [ Solved ]
« Reply #8 on: May 10, 2018, 06:44:52 pm »
Code: [Select]
Error using plot
Vectors must be the same length.

Error in Untitled (line 136)
plot(wmm,Temm,'r',wmm,Temm,'or','linewidth',1.5);

That's a very detailed error message, so I won't spoon feed you the answer.

Go through it systematically: What are the lengths of the 'wmm' and 'Temm' variables?
« Last Edit: May 10, 2018, 06:46:23 pm by mbless »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf