⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.m

📁 最优化计算的牛顿法+共轭梯度法的MATLAB程序
💻 M
字号:
function y=main(x)
%This program uses the steepest_down + conjugate_grad method
%to calculate the minimum of the function f(x)=x(1)^2+2*x(2)^2

format long
eps=input('please input your accuracy:');
%eps is the demmanded accuracy on the norm of 
%the gradient of the objective function

m=1;
%m is the count of the iteration step of the algorithm

iterstep(1,:)=x;
%iterstep contains the intermediate points of iteration

while m<=3
   while norm(gradobject1(x))>eps
     grad=gradobject1(x);
     alpha=goldsplictobj(x);
     x=x-alpha*grad;
     iterstep(m+1,:)=x;
     m=m+1;
  end
end

while norm(gradobject1(x))>eps
    x1=iterstep(m-1,:);
    x2=iterstep(m,:);
    grad1=gradobject1(x1);
    grad2=gradobject1(x2);
    beta=(norm(gradobject1(x2))/norm(gradobject1(x1)))^2;
    S=-grad2-beta*grad1;
    x2=x2-alpha*S;
    x=x2;
    iterstep(m+1,:)=x;
    m=m+1;
end


step=max(size(iterstep))-1
x
iterstep
plot(iterstep(:,1),iterstep(:,2));
%Draw the search trajectory 




⌨️ 快捷键说明

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