开发者

what's wrong with the code,please help me.i want to display the result from j=1 till j= 24

lambda0 = 9.6;
gamma0  = 0.0016;
Pload = 900;
nj=1;
AvW = 32e6;
t = 12;
%thermal plant%%%
ath = 0.002;
bth = 8;
gamth = 1200;
cth = 0;
Pth0 = (lambda0 - (nj*bth))/((2*nj*ath)-(2*cth*lambda0));
%%%%%hydro plant%%%%%
ah = 6000;
bh = 100000;
ch = 100;
Ph0  = (lambda0 - (nj*ah*gamma0))/(2*lambda0*ch); 
Tl = 0.0000045;



%%%%%%%%%%%lambda%%%%%%%%%%%%%%%%%%%%%%
j=1;
for j=1:24

  x = Pload - Ph0 - Pth0;

  e1   = 0.1;

  while x > e1

      lambda = lambda0 + 0.25;
      Pth    = (lambda - (nj*bth))/((2*nj*ath)-(2*cth*lambda));
      Ph     = (lambda - (nj*ah*gamma0))/(2*lambda*ch);
      Ploss  = 0.0000045 * Ph^2; 
      x = Pload + Ploss - Ph - Pth;

      if x < e1
      lambda = lambda0;
      Pth    = (lambda - (nj*bth))/((2*nj*ath)-(2*cth*lambda));
      Ph     = (lambda - (nj*ah*gamma0))/(2*lambda*ch);
      Ploss  = 0.0000045 * Ph^2;
      end 

  W = bth + ath*Ph;
  fprintf('W=%.3f',W);
  x = Pload + Ploss - Ph - Pth; 
  e2 = 50 ;
  dW = W - AvW; 
  end 
end
 while dW > e2

 lambda = (nj *(gamma0*ah)-(2*ath*bth))/((2*cth*Pth)-(2*Tl*Ph));
 x = Pload-Ph-Pth;
 while x(1)> e1

     lambda = lambda + 0.25;
     gamma  = gamma0 + 0.00001;
     Pth    = (lambda - (nj*bth))/((2*nj*ath)-(2*cth*lambda));
     Ph     = (lambda - (nj*ah*gam))/(2*lambda*ch);
     Ploss  = 0.0000045 * Ph^2; 
     x      = Pload + Ploss - Ph - Pth;

     if x(1)开发者_StackOverflow社区< e1
     lambda = lambda0;
     Pth    = (lambda - (nj*bth))/((2*nj*ath)-(2*cth*lambda));
     Ph     = (lambda - (nj*ah*gamma))/(2*lambda*ch);
     Ploss  = 0.0000045 * Ph^2;  
     x      = Pload + Ploss - Ph - Pth;
     W      = bth + ath*Ph;
     fprintf('w=%.3f',W);
     end
 end
  tot = W * t ;

 if e2 > tot
  fprintf('\t%.3f',lambda);
  fprintf('\t%.3f',Pth);
  fprintf('\t%.3f',Ph);
  fprintf('\t%.3f',gamma);
  fprintf('\n');
 end
 end 


Your loop says for j=1:1. Shouldn't that be for j=1:24?


Your problem is that your while loop is an infinite loop. The first 5 lines in the first while loop are constants, hence x, which comes out to be 437.5, is always greater than e1, so your loop never terminates. Also, I don't see the loop index being used anywhere, so essentially, it makes no difference if you loop it or not.

I'm guessing you've confused yourself with too many non-descriptive variables. I second Carl's suggestion that you try to bring some order in the naming, and the flow of your code and then you'll see for yourself how to fix it (hint: I've already told you where to look).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜