siscer

Upload: neveralone11

Post on 07-Jul-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/19/2019 Siscer

    1/1

    function [xopt,fmin,it]=simpelso(N,maxit)

    %to find minimum of single var function

    dim = 1; %dimension of the problem

    upbnd = !; %upper bound for init of the s"arm

    l"bnd = 1#!; %lo"er bound for init of the s"arm

    %initiali$ing s"arm and velocities

    x = rand(N,dim)(upbnd&l"bnd) ' l"bnd;

    v = rand(N,dim); %ecepatan a"al

    [brs,ol]=si$e(x);

    f=$eros(N,1);

    rhomax=!;rhomin=!*;

    for it=1+maxit

      rho(it)=rhomax&((rhomax&rhomin)maxit)it;

    end

     

    for i=1+brs

      f(i)=fungsi#(x(i,+));

    end

     

    %v=$eros(brs,ol);

    it=1;

    -best=x;

    fbest=f

    [minf,id]=min(f);

    .best=x(id,+);

    lastbest=[! !];

    minftot=[];

     

    "hile it/maxit

      r1=rand;r#=rand;

      for 0=1+brs

      v(0,+)=rho(it)v(0,+)'r1(-best(0,+)&x(0,+))'r#(.best&x(0,+));

      x(0,+)=x(0,+)'v(0,+);

      f(0)=fungsi#(x(0,+));  end

      %update -best

      changero" = f / fbest;

    fbest=fbest(1&changero")'fchangero";

    -best(find(changero"),+)=x(find(changero"),+);

    [minf,id]=min(fbest);

    minftot=[minftot;minf];

    gbest=-best(id,+);

    if sum(var(-best))/1e&

      brea

    end

    it=it'1

    lastbest=.best;end

    xopt=.best;

    fmin=minf;

    plot(minftot)

    %%%%%%%%%%%%%%

    function f=fungsi#(x)

    f=(1!!&x!2#;