当前位置:网站首页>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
边栏推荐
猜你喜欢
Man man notes and @ reboot usage of crontab
TLC5615 based multi-channel adjustable CNC DC regulated power supply, 51 single chip microcomputer, including proteus simulation and C code
Swift:Entry of program、Swift调用OC、@_silgen_name 、 OC 调用Swift、dynamic、String、Substring
关于UDP接收icmp端口不可达(port unreachable)
A good tool: aardio
Tongxin UOS php7 2.3 upgrade to php7.0 two point two four
基于TLC5615的多路可调数控直流稳压电源,51单片机,含Proteus仿真和C代码等
Branch statement of process control
DVWA之暴力破解(Brute Force)Low-->high
Parameter stack pressing problem of C language in structure parameter transmission
随机推荐
c语言在结构体传参时参数压栈问题
外包干了四年,废了...
【无标题】
Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
一篇博客让你学会在vscode上编写markdown
关于在vs中使用scanf不安全的问题
【Proteus仿真】自动量程(范围<10V)切换数字电压表
想要成为架构师?夯实基础最重要
Use cases of the arrays class
单片机的函数信号发生器,输出4种波形,频率可调,原理图,仿真和C程序
TLC5615 based multi-channel adjustable CNC DC regulated power supply, 51 single chip microcomputer, including proteus simulation and C code
Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
LotusDB 设计与实现—1 基本概念
C语言知识点精细详解——初识C语言【1】——你不能不知的VS2022调试技巧及代码实操【1】
QT actual combat: Yunxi chat room
Electronic scale weighing system design, hx711 pressure sensor, 51 single chip microcomputer (proteus simulation, C program, schematic diagram, thesis and other complete data)
SHT11传感器的温度湿度监控报警系统单片机Proteus设计(附仿真+论文+程序等)
Redis源码分析之HSET流程与ziplist
顺序栈的基本操作
I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another