当前位置:网站首页>Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
2022-04-23 14:35:00 【I channel I】
This article contains the following
1、 Draw the algorithm flow chart of the steepest descent method ;
2、MATLAB Write gradient calculation function using numerical differentiation method ( Functional expression M file );
3、MATLAB Write the function of steepest descent method to solve unconstrained optimization problem , It is required to use the golden section method for accurate one-dimensional search , Calculate the gradient by numerical differentiation ( Functional expression M file , Precision set to epson Adjustable );
4、MATLAB Write the function of steepest descent method to solve unconstrained optimization problem , Required Wolfe-Powell Inexact one-dimensional search , Calculate the gradient by numerical differentiation ( Functional expression M file , Precision set to epson Adjustable );
5、MATLAB Programming ( imperative M file ), Using exact search and imprecise search respectively The steepest descent method , Solve the following problem :
Accuracy of 0.001, The initial point is (-1,1);
Change the initial point to (-1.2,1) Rerun , Run the observation .
In this experiment, the function is used separately function Calculation
function y=f(x)
if(length(x)==1)
global xk;
global pk;
x=xk+x*pk;
end
y=100*(x(2)-x(1)^2)^2+(1-x(1))^2;
1. Algorithm flow chart of steepest descent method
2、MATLAB Write gradient calculation function using numerical differentiation method ( Functional expression M file );
function g=shuzhiweifenfa(x)
for i = 1:length(x)
m=zeros(1,length(x));
m(i)=(10^-3)/2;
g(i)=f(x+m)-f(x-m);
end
g=g/10^-3;
3、 The steepest descent method is a function for solving unconstrained optimization problems , The golden section method is used to search one-dimensional accurately , Calculate the gradient by numerical differentiation ( Functional expression M file , Precision set to epson Adjustable );
function x=zuisuxiajiangfa_hjfg(e,x)
%step 1
% Not used k, Store only the value of the current iteration .
global xk;
global pk;
while 1
%step 2
g=shuzhiweifenfa(x);
%step 3
% The norm uses the square sum and the open root sign
if sqrt(sum(g.^2))<=e
return;
end
pk=-g;
xk=x;
% These two functions are shown in the previous code (matlab General algorithm of unconstrained optimization )
[a,b,c]=jintuifa(0,0.1);
a=huangjinfenge(a,c,10^-4);
%step 4
x=x+a*pk;
end
4、 The steepest descent method is a function for solving unconstrained optimization problems , Required Wolfe-Powell Inexact one-dimensional search , Calculate the gradient by numerical differentiation ( Functional expression M file , Precision set to epson Adjustable );
function a=Wolfe_Powell(x,pk)
%step 1
u=0.1;
b=0.5;
a=1;
n=0;
m=10^100;
%step 2
fx=f(x);
g=shuzhiweifenfa(x);
while 1
xk=x+a*pk;
fxk=f(xk);
gk=shuzhiweifenfa(xk);
if (fx-fxk)>=(-u*a*g*pk.')%(3-1)
if (gk*pk.')>=(b*g*pk.')%(3-2)
return;
else
%step 4
n=a;
a=min(2*a,(a+m)/2);
end
else
%step 3
m=a;
a=(a+n)/2;
end
end
function x=zuisuxiajiangfa_Wolfe(e,x)
%step 1
% Not used k, Store only the value of the current iteration .
while 1
%step 2
g=shuzhiweifenfa(x);
%step 3
% The norm uses the square sum and the open root sign
if sqrt(sum(g.^2))<=e
return;
end
pk=-g;
a=Wolfe_Powell(x,pk);
%step 4
x=x+a*pk;
end
5、 Using exact search and imprecise search respectively The steepest descent method , problem :
clear
clc
for i=1:2
if(i==1)
x=[-1,1];
fprintf('=========================');
fprintf('\nx=%f\t\t%f\n',x(1),x(2));
fprintf('=========================\n');
else
x=[-1.2,1];
fprintf('=========================');
fprintf('\nx=%f\t\t%f\n',x(1),x(2));
fprintf('=========================\n');
end
fprintf(' The steepest descent method for accurate search :\n');
x_=zuisuxiajiangfa_hjfg(10^-3,x);
fprintf('x*=%f\t%f\n',x_(1),x_(2));
fprintf('f(x)=%f\n',f(x_));
fprintf(' The steepest descent method of imprecise search \n');
x_=zuisuxiajiangfa_Wolfe(10^-3,x);
fprintf('x*=%f\t%f\n',x_(1),x_(2));
fprintf('f(x)=%f\n',f(x_));
end
result :
版权声明
本文为[I channel I]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231433048632.html
边栏推荐
- 顺序表的操作,你真的学会了吗?
- SHT11传感器的温度湿度监控报警系统单片机Proteus设计(附仿真+论文+程序等)
- Detailed explanation of SAR command
- MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program
- 矩阵交换行列
- 本以为能躺着进华为,结果陆续收到京东/滴滴/爱奇艺offer的我迷茫了
- AT89C52 MCU frequency meter (1Hz ~ 20MHz) design, LCD1602 display, including simulation, schematic diagram, PCB and code, etc
- 全连接层的作用是什么?
- 初始c语言大致框架适合复习和初步认识
- QT interface optimization: QT border removal and form rounding
猜你喜欢
MDS55-16-ASEMI整流模块MDS55-16
Qt实战:云曦聊天室篇
C语言知识点精细详解——初识C语言【1】
C语言知识点精细详解——初识C语言【1】——你不能不知的VS2022调试技巧及代码实操【1】
AT89C52 MCU frequency meter (1Hz ~ 20MHz) design, LCD1602 display, including simulation, schematic diagram, PCB and code, etc
流程控制之分支语句
【Servlet】Servlet 详解(使用+原理)
redis的五种数据类型
基于TLC5615的多路可调数控直流稳压电源,51单片机,含Proteus仿真和C代码等
直流可调稳压电源的Proteus仿真设计(附仿真+论文等资料)
随机推荐
Tongxin UOS uninstall php7 2.24, install php7 4.27 ; Uninstall and then install PHP 7.2.34
I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another
外包干了四年,废了...
Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)
【工厂模式详解】工厂方法模式
Four ways of SSH restricting login
MySQL报错packet out of order
Logical volume creation and expansion
关于UDP接收icmp端口不可达(port unreachable)
Matrix exchange row and column
Arduino for esp8266串口功能简介
C语言知识点精细详解——数据类型和变量【1】——进位计数制
async void 导致程序崩溃
AT89C51 MCU digital voltmeter development, measuring range 0 ~ 5V, proteus simulation, schematic diagram, PCB and C program, etc
A good tool: aardio
flannel 原理 之 TUN模式
Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
source insight via samba
直流可调稳压电源的Proteus仿真设计(附仿真+论文等资料)
c语言在结构体传参时参数压栈问题