home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 4.ddi / OPTIM.DI$ / SEMIFUN.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  1.9 KB  |  62 lines

  1. function [f, gall, NPOINT, NEWLAMBDA, OLDLAMBDA, LOLD, s] = semifun( x, LAMBDA, NEWLAMBDA, OLDLAMBDA, POINT, fun, ntheta, flag, s, P1,P2,P3,P4,P5,P6,P7,P8,P9,P10)
  2. %SEMIFUN Translation routine for semi-infinite optimization.
  3. %    Function used by SEMINF to make semi-infinite problems
  4. %    look like regular constrained optimization problems.
  5.  
  6. g=[]; f=[]; % Tell parser that f and g are variables.
  7. eval(fun)
  8.  
  9.  
  10. gcnt = length(g)+1; 
  11. gncnt = gcnt; 
  12. NPOINT = POINT; 
  13. if length(POINT) == 0
  14.     POINT = zeros(ntheta, 1);
  15.     LAMBDA = zeros(gcnt-1, 1);
  16.     NEWLAMBDA = zeros(gcnt-1, 1);
  17. end
  18.     
  19. delta = []; 
  20. gall = g(:); 
  21. chg = 0; 
  22. if flag  > 0
  23.     NEWLAMBDA = LAMBDA;
  24. end
  25.  
  26. for i= 1:ntheta
  27.         [gt,d]=eval(['findmax(t',int2str(i),',flag<0)']);
  28. % Find all the maximum points of the data
  29.         nmax=length(gt);
  30. % If the number of maxima is different from las time then change
  31. % LAMBDA and OLDLAMBDA.
  32. % Since the number of maxima is changing then we must try to
  33. % allocate elements of LAMBDA to each of the main peaks.
  34.         nl=POINT(i);
  35. % If the number of maxima is different during  a gradient calculation
  36. % then assign first 'nl' gradients to gt
  37.     if flag > 0
  38.         NPOINT(i,1) = nmax; 
  39.     end
  40.     if flag < 0
  41.         if s~=NaN , s(i,:) = s(i,:).*d;    end
  42.     end
  43.         if nmax~=nl & flag > 0
  44.         chg = 1; 
  45.                 [dum,ind]=sort(-gt);
  46.                 indl=find(LAMBDA(gcnt:gcnt+nl-1)>0);
  47.                 if length(indl)>nmax, indl=indl(1:nmax); end
  48.                 sortl=zeros(nmax,1);
  49.                 sortl(sort(ind(1:length(indl))))=LAMBDA(gcnt-1+indl);
  50.                 NEWLAMBDA=[NEWLAMBDA(1:gncnt-1 );sortl;LAMBDA(gcnt+nl:length(LAMBDA))]; 
  51.         LOLD=NEWLAMBDA;
  52.         end
  53.         gncnt=min(length(NEWLAMBDA)+1, gncnt+nmax);
  54.         gcnt=gcnt+nl;
  55.         delta=[delta;d];
  56.         gall=[gall;gt];
  57. end
  58. if  chg | (flag> 0 & length(OLDLAMBDA) ~= length(gall))
  59.         OLDLAMBDA = NEWLAMBDA + max(OLDLAMBDA);
  60. end
  61.  
  62.