Essays.club - Получите бесплатные рефераты, курсовые работы и научные статьи
Поиск

Условная Оптимизация

Автор:   •  Март 4, 2019  •  Практическая работа  •  1,847 Слов (8 Страниц)  •  358 Просмотры

Страница 1 из 8

УСЛОВНАЯ ОПТИМИЗАЦИЯ

Цель работы: Ознакомится с методами условной оптимизации, выполнить поиск минимума функций различными алгоритмами.

Ход работы.

1. Воспроизвели пример 4, исследовать работу трех алгоритмов из разных начальных точек, принадлежащих и не принадлежащих допустимой области.

1.1 Воспроизвели пример 4 с использование алгоритма interior-point (метод внутренней точки).

Листинг программы

function  history = runfmincon11(x0)

 history.x = [];

 history.fval = [];

 A=[3 1;-1 1];b=[8;3];

 [X,Y]=meshgrid(0:0.02:3.5,0:0.02:6);Z=primfun_g(X,Y);

[c,h]=contour(X,Y,Z,[0.007 0.025 0.1 0.5 2 5 10 15 ...

20 27 35 45],'blue');

clabel(c,h,[0.5 5 15 27],'FontSize',7);

hold on;plot([8/3 1.25],[0 4.25],'g-','linewidth',2.3);

plot([0 1.25],[3 4.25],'g-','linewidth',2);

text(1,1.8,'The feasible region');

xlabel('x1'); ylabel('x2'); text(x0(1),x0(2)+0.2,'x0');

title('Minimization by fmincon');

options = optimset('outputfcn',@outfun,'display',...

'off','Algorithm','interior-point');

[x,fval,exitflag,output]=fmincon(@primfun,x0,A,b,...

[],[],[],[],[],options)

 y=history.x(:,1);z=history.x(:,2);

 hold on;plot(y,z,'b.',y,z,'r-');

 function stop = outfun(x,optimValues,state)

 stop = false;

 switch state

 case 'init'

 hold on

 case 'iter'

     history.fval = [history.fval;...

optimValues.fval];

 history.x = [history.x; x];

 end

 end

end

Результат выполнения программы решения с графиком

>> x0=[3 2];history=runfmincon11(x0)

x = 1.6049    3.1852

fval =0.0250

exitflag = 1

output =

iterations: 13

funcCount: 43

constrviolation: 0

stepsize: 5.6982e-007

algorithm: 'interior-point'

firstorderopt: 4.0000e-007

 cgiterations: 0

message: [1x834 char]

[pic 1]

Рисунок 1 - Поиск минимума методом внутренней точки

Для  точки, не принадлежащей допустимой области.

>> x0=[5 10];history=runfmincon11(x0)

x =

    1.6049    3.1852

fval =

    0.0250

exitflag =

     1

output =

         iterations: 15

          funcCount: 48

    constrviolation: 0

           stepsize: 3.7641e-004

          algorithm: 'interior-point'

      firstorderopt: 4.4128e-007

       cgiterations: 0

            message: [1x834 char]

history =

       x: [16x2 double]

    fval: [16x1 double]

[pic 2]

Рисунок 2 – Поиск минимума методом внутренней точки из точки, не принадлежащей области допустимых значений

1.2 Рассмотри данный пример с помощью Метода Active Set.

Листинг программы

function  history = runfmincon111(x0)

 history.x = [];

 history.fval = [];

 A=[3 1;-1 1];b=[8;3];

 [X,Y]=meshgrid(0:0.02:3.5,0:0.02:6);Z=primfun_g(X,Y);

[c,h]=contour(X,Y,Z,[0.007 0.025 0.1 0.5 2 5 10 15 ...

20 27 35 45],'blue');

clabel(c,h,[0.5 5 15 27],'FontSize',7);

hold on;plot([8/3 1.25],[0 4.25],'g-','linewidth',2.3);

plot([0 1.25],[3 4.25],'g-','linewidth',2);

text(1,1.8,'The feasible region');

xlabel('x1'); ylabel('x2'); text(x0(1),x0(2)+0.2,'x0');

title('Minimization by fmincon');

options = optimset('outputfcn',@outfun,'display',...

'off','Algorithm','active-set');

[x,fval,exitflag,output]=fmincon(@primfun,x0,A,b,...

[],[],[],[],[],options)

 y=history.x(:,1);z=history.x(:,2);

 hold on;plot(y,z,'b.',y,z,'r-');

 function stop = outfun(x,optimValues,state)

 stop = false;

 switch state

 case 'init'

 hold on

 case 'iter'

     history.fval = [history.fval;...

optimValues.fval];

 history.x = [history.x; x];

 end

 end

end

Результат выполнения программы решения

>> x0=[3 2];history=runfmincon111(x0)

x =

    1.6049    3.1852

fval =

    0.0250

exitflag =

     5

output =

         iterations: 7

          funcCount: 21

       lssteplength: 1

           stepsize: 1.4155e-005

          algorithm: [1x44 char]

      firstorderopt: 6.9666e-005

    constrviolation: 0

            message: [1x843 char]

history =

       x: [7x2 double]

    fval: [7x1 double]

[pic 3]

Рисунок 3 - Поиск минимума методом Active Set.

...

Скачать:   txt (13.4 Kb)   pdf (989.9 Kb)   docx (706.4 Kb)  
Продолжить читать еще 7 страниц(ы) »
Доступно только на Essays.club