资源简介

matlab脚本文件,通用代码,求现代设计方法中二维无约束优化问题的最优解

资源截图

代码片段和文件信息


%%    
X_1_0=[0;0];
precise=0.0001;
S_1_1=[1;0];
S_1_2=[0;1];
k=1
syms alpha1 alpha2 alpha3  x1 x2 X_1_1 X_1_2;
X=[x1;x2];
% fx=2*x1^2+x2^2-x1*x2;
% fx=x1^2+2*x2^2-4*x1-2*x1*x2;
fx=60-10*x1-4*x2+x1^2+x2^2-x1*x2;
while 1

    %求解k次迭代第二个点的函数值
    F_1_0=subs(fxX X_1_0)
%     disp(F_1_0)
    
    %求解k次迭代第二个点的函数值
    X_1_1=X_1_0+alpha1*S_1_1;
    F1=subs(fxX X_1_1);
    f1=diff(F1);
    alpha1N=solve(f1alpha1);
    X_1_1=X_1_0+alpha1N*S_1_1;
    F_1_1=subs(fxX X_1_1)
%     disp(F_1_1)
    
    %求解k次迭代第三个点的函数值
    X_1_2=X_1_1+alpha2*S_1_2;
    F2=subs(fxX X_1_2);
    f2=diff(F2);
    alpha2N=solve(f2alpha2);
    X_1_2=X_1_1+alpha2N*S_1_2;
    F_1_2=subs(fxX X_1_2)
%     disp(F_1_2)
    
    %计算共轭方向
    S_1=X_1_2-X_1_0
    X_1_3=2*X_1_2-X_1_0;
    F_1_3=subs(fxX X_1_3)
%     disp(F_1_3)
    
    data_1_1=F_1_0-F_1_1;
    data_1_2=F_1_1-F_1_2;
    if(data_1_1>data_1_2)
        S_m_k=S_1_1;
        data_m_k=data_1_1;
        f_1=(F_1_0-2*F_1_2+F_1_3)*(F_1_0-F_1_2-data_m_k)^2;
        f_2=(0.5*data_m_k*(F_1_0-F_1_3)^2);
        if((F_1_3            X_1=X_1_2+alpha3*S_1;
            F3=subs(fxX X_1);
            f3=diff(F3);
            alpha3N=solve(f3alpha3)
            X_1=X_1_2+alpha3N*S_1
            X_2_0=X_1;
            S_1_1=S_1_2
            S_1_2=S_1
            if norm(X_2_0-X_1_0)<=precise
                break;
            else
                X_1_0=X_1;
                X_star=X_2_0;
                X_star=vpa(X_star)
                f_star=subs(fxX X_star);
                f_star=vpa(f_star)
                fprintf(‘最优解%f‘ X_star)
                k=k+1
            end
            
        else
            if F_1_3>F_1_2
               X_2_0=X_1_2;
               if sqrt((X_2_0(11)-X_1_0(11)).^2+(X_2_0(21)-X_1_0(21)).^2)<=precise
                   break;
               else
                   X_1_0=X_2_0;
                   X_star=X_2_0;
                   X_star=vpa(X_star)
                   f_star=subs(fxX X_star);
                   f_star

评论

共有 条评论