m0_63192263 2021-10-20 08:48
浏览 224
已结题

完成/改进附件中最速下降法的MATLAB代码,可与其他算法结合求解30维Rosenbrock函数的最优解

function [F0,x0,FE] = LineSearchDemo()

nVar = 30; % Number of variables

x0 = 2*ones(1,nVar); % DO NOT CHANGE. Initial position.

% p0 = [1;1]; % Use your own search direction instead

tol = 1e-6; % Tolerance

FEmax = 2e6; % Maximum number of function evalution

alpha = 1; % Initial step length

F0 = Rosenbrock(x0); % Intial functino value

FE = 1; % Number of function evaluations

while F0 > tol && FE < FEmax % Step if reach tolerance or exceeds maximum function eval.

g = gradient(x0,F0); % The gradient on current x

FE = FE + nVar; % Finding gradient costs nVar FE

p = -g; % Search direction

xnew = x0 + alpha*p; % Next step

Fnew = Rosenbrock(xnew); % Function value of the next step

FE = FE + 1; % Update FE

if Fnew < F0 % If better solution found

    

    

    

else

    

end

end

function y = Rosenbrock(x) % The Rosenbrock function

nVar = size(x,2);

y = sum(100.*(x(:,1:nVar-1).^2-x(:,2:nVar)).^2+(x(:,1:nVar-1)-1).^2,2);

function g = gradient(x,F0) % Find the gradient of the current point

nVar = size(x,2);

d = sqrt(eps); % A small disturbance

X = repmat(x,nVar,1) + eye(nVar)*d; % Add disturbance to each element of x

g = (Rosenbrock(X)-F0)'/d; % You may use this line to debug your code for

% efficiency, but MUST NOT when you are using the Profiler

%--------------------------------------------------------------------------

% This part is only used when you need to submit the report. For debuging,

% comment this part.

% g = zeros(1,nVar);

% for ii = 1:nVar

% g(ii) = (Rosenbrock(X(ii,:))-F0)/d;

% end

%--------------------------------------------------------------------------大体框架是这样的,哪位大神会呀,只要改几行代码即可。要求是: 完成/改进附件中最速下降法的MATLAB代码,可与其他算法结合求解30维Rosenbrock函数的最优解;

2) 允许使用线搜索以外的算法,但必须手动实现。直接调用系统内置功能将被视为不合格

3) 无论进行何种更改,每次函数计算后都必须更新FE(函数求值,目标函数的调用次数);

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 10月28日
    • 创建了问题 10月20日

    悬赏问题

    • ¥15 关于博途V17进行仿真时无法建立连接问题
    • ¥15 请问下这个红框里面是什么文档或者记事本编辑器
    • ¥15 机器学习教材中的例题询问
    • ¥15 求.net core 几款免费的pdf编辑器
    • ¥15 为什么安装HCL 和virtualbox之后没有找到VirtualBoxHost-OnlyNetWork?
    • ¥15 C# P/Invoke的效率问题
    • ¥20 thinkphp适配人大金仓问题
    • ¥20 Oracle替换.dbf文件后无法连接,如何解决?(相关搜索:数据库|死循环)
    • ¥15 数据库数据成问号了,前台查询正常,数据库查询是?号
    • ¥15 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)