al_obj.m

来自「求解非线性最化的局部最优解,matlab,matlab例程」· M 代码 · 共 24 行

M
24
字号
%AL_function
% the N_equ the number of the equality , and the N_inequ the number of the
% inequality
function  f =AL_obj(x)
global r_al pena N_equ N_inequ;
h_equ=0;
h_inequ=0;
N=N_equ+N_inequ;
temp_constrains=constrains( x );
%% the equality constrains part;
    for i=1:N
    %% the equality constrains part;
    if N_equ~=0 && N_equ>=i
            h_equ=h_equ - r_al(i)*temp_constrains(i) + (pena/2)* temp_constrains(i).^2;
    end
    %% the inequality
    if N_inequ~=0 && i>N_equ    
        temp=0;
        temp=max(0,( r_al(i)-pena*temp_constrains(i)));
        h_inequ=h_inequ + (0.5/pena)*( temp.^2- r_al(i).^2 );      
    end
end
f=obj(x)+h_equ+h_inequ;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?