当前位置: 首页 > news >正文

网页翻译不了杭州seo公司

网页翻译不了,杭州seo公司,卖鞋子网站建设策划书,正规少儿编程排名🔗 运行环境:Matlab 🚩 撰写作者:左手の明天 🥇 精选专栏:《python》 🔥 推荐专栏:《算法研究》 #### 防伪水印——左手の明天 #### 💗 大家好🤗&#x1f91…

🔗 运行环境:Matlab

🚩 撰写作者:左手の明天

🥇 精选专栏:《python》

🔥  推荐专栏:《算法研究》

#### 防伪水印——左手の明天 ####

💗 大家好🤗🤗🤗,我是左手の明天!好久不见💗

💗今天开启新的系列——重新定义matlab强大系列💗

📆  最近更新:2023 年 09 月 23 日,左手の明天的第 291 篇原创博客

📚 更新于专栏:matlab

#### 防伪水印——左手の明天 ####


约束优化定义

约束最小化问题求向量 x,在满足 x 取值约束的前提下,使得标量函数 f(x) 取得局部最小值:

使得以下一项或多项成立:c(x) ≤ 0, ceq(x) = 0, A·x ≤ b, Aeq·x = beq, l ≤ x ≤ u。 

基于问题求解非线性优化

通过使用基于问题的方法寻找具有非线性约束的非线性目标函数的最小值。要使用基于问题的方法找到非线性目标函数的最小值,首先将目标函数编写为文件或匿名函数。目标函数是

type objfunxfunction f = objfunx(x,y)
f = exp(x).*(4*x.^2 + 2*y.^2 + 4*x.*y + 2*y - 1);
end

创建优化问题变量 x 和 y

x = optimvar('x');
y = optimvar('y');

使用优化变量的表达式创建目标函数。

obj = objfunx(x,y);

创建一个以 obj 为目标函数的优化问题。

prob = optimproblem('Objective',obj);

创建一个使解位于倾斜椭圆中的非线性约束,指定为

使用优化变量的不等式表达式创建约束。

TiltEllipse = x.*y/2 + (x+2).^2 + (y-2).^2/2 <= 2;

在问题中包含该约束。

prob.Constraints.constr = TiltEllipse;

创建一个结构体,将初始点表示为 x = –3y = 3

x0.x = -3;
x0.y = 3;

检查此问题。

show(prob)OptimizationProblem : Solve for:x, yminimize :(exp(x) .* (((((4 .* x.^2) + (2 .* y.^2)) + ((4 .* x) .* y)) + (2 .* y)) - 1))subject to constr:((((x .* y) ./ 2) + (x + 2).^2) + ((y - 2).^2 ./ 2)) <= 2

求解。

[sol,fval] = solve(prob,x0)Solving problem using fmincon.Local minimum found that satisfies the constraints.Optimization completed because the objective function is non-decreasing in 
feasible directions, to within the value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.
sol = struct with fields:x: -5.2813y: 4.6815fval = 0.3299

尝试不同起点。


x0.x = -1;
x0.y = 1;
[sol2,fval2] = solve(prob,x0)Solving problem using fmincon.Feasible point with lower objective function value found.Local minimum found that satisfies the constraints.Optimization completed because the objective function is non-decreasing in 
feasible directions, to within the value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.sol2 = struct with fields:x: -0.8210y: 0.6696fval2 = 0.7626

绘制椭圆、目标函数等高线和两个解。

f = @objfunx;
g = @(x,y) x.*y/2+(x+2).^2+(y-2).^2/2-2;
rnge = [-5.5 -0.25 -0.25 7];
fimplicit(g,'k-')
axis(rnge);
hold on
fcontour(f,rnge,'LevelList',logspace(-1,1))
plot(sol.x,sol.y,'ro','LineWidth',2)
plot(sol2.x,sol2.y,'ko','LineWidth',2)
legend('Constraint','f Contours','Global Solution','Local Solution','Location','northeast');
hold off

Figure contains an axes object. The axes object contains 4 objects of type implicitfunctionline, functioncontour, line. One or more of the lines displays its values using only markers These objects represent Constraint, f Contours, Global Solution, Local Solution.

解位于非线性约束边界上。等高线图显示这些是仅有的局部最小值。该图还显示在 [–2,3/2] 附近存在一个平稳点,在 [–2,0] 和 [–1,4] 附近存在局部最大值。

Matlab求解函数

求解无约束极小值 

基于求解器求解

在matlab工具箱中,用于求解无约束极小值问题的函数有 fminunc 和 fminsearch (局部最优化算法):

fminunc(采用拟牛顿法(QN),是一种使用导数的算法)
[x, fval, exitflag, output, grad, hessian] = fminunc(fun, x0, options)

输入参数:

  • fun 为要计算最小值的函数;
  • x0 为初始点;
  • options 为优化选项。

输出参数:

  • x 为解,
  • fval 为解处的目标函数值;
  • exitflag 为fminunc 停止的原因,
  • output 为有关优化过程的信息,
  • grad 为解处的梯度,
  • hessian 为逼近 Hessian 矩阵。

最小化函数:

fun = @(x)3*x(1)^2 + 2*x(1)*x(2) + x(2)^2 - 4*x(1) + 5*x(2);

调用 fminunc 以在 [1,1] 附近处求 fun 的最小值。

x0 = [1,1];
[x,fval] = fminunc(fun,x0)Local minimum found.Optimization completed because the size of the gradient is less than
the value of the optimality tolerance.x = 1×22.2500   -4.7500fval = -16.3750
fminsearch(采用Nelder-Mead单纯形法,是一种直接搜索法)
[x, fval, exitflag, output, grad, hessian] = fminunc(fun, x0, options)

输入参数:

  • fun 为要计算最小值的函数;
  • x0 为初始点;
  • options 为优化选项。

输出参数:

  • x 为解,
  • fval 为解处的目标函数值;
  • exitflag 为fminunc 停止的原因,
  • output 为有关优化过程的信息。

监视优化过程

options = optimset('PlotFcns',@optimplotfval);

将目标函数设置为 Rosenbrock 函数,

该函数的最小值在 x = [1,1] 处,最小值为 0

将起始点设置为 x0 = [-1.2,1] 并使用 fminsearch 计算 Rosenbrock 函数的最小值。

fun = @(x)100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
x0 = [-1.2,1];
x = fminsearch(fun,x0,options)

Figure Optimization Plot Function contains an axes object. The axes object with title Current Function Value: 8.17766e-10, xlabel Iteration, ylabel Function value contains a line object which displays its values using only markers.

x = 1×21.0000    1.0000

检查优化过程

在优化进行期间和优化结束后检查优化结果。

将选项设置为提供迭代输出,从而在求解器运行时提供有关优化的信息。此外,将绘图函数设置为在求解器运行时显示目标函数值。

options = optimset('Display','iter','PlotFcns',@optimplotfval);

设置目标函数和起始点。

function f = objectivefcn1(x)
f = 0;
for k = -10:10f = f + exp(-(x(1)-x(2))^2 - 2*x(1)^2)*cos(x(2))*sin(2*x(2));
end

将 objectivefcn1 的代码作为文件包含在路径中。

x0 = [0.25,-0.25];
fun = @objectivefcn1;

获取所有求解器输出。在求解器运行完毕后,使用这些输出检查结果。

[x,fval,exitflag,output] = fminsearch(fun,x0,options)
 Iteration   Func-count         f(x)         Procedure0            1         -6.70447         1            3         -6.89837         initial simplex2            5         -7.34101         expand3            7         -7.91894         expand4            9         -9.07939         expand5           11         -10.5047         expand6           13         -12.4957         expand7           15         -12.6957         reflect8           17         -12.8052         contract outside9           19         -12.8052         contract inside10           21         -13.0189         expand11           23         -13.0189         contract inside12           25         -13.0374         reflect13           27          -13.122         reflect14           28          -13.122         reflect15           29          -13.122         reflect16           31          -13.122         contract outside17           33         -13.1279         contract inside18           35         -13.1279         contract inside19           37         -13.1296         contract inside20           39         -13.1301         contract inside21           41         -13.1305         reflect22           43         -13.1306         contract inside23           45         -13.1309         contract inside24           47         -13.1309         contract inside25           49          -13.131         reflect26           51          -13.131         contract inside27           53          -13.131         contract inside28           55          -13.131         contract inside29           57          -13.131         contract outside30           59          -13.131         contract inside31           61          -13.131         contract inside32           63          -13.131         contract inside33           65          -13.131         contract outside34           67          -13.131         contract inside35           69          -13.131         contract insideOptimization terminated:the current x satisfies the termination criteria using OPTIONS.TolX of 1.000000e-04 and F(X) satisfies the convergence criteria using OPTIONS.TolFun of 1.000000e-04 
x =-0.1696   -0.5086fval =-13.1310exitflag =1output = struct with fields:iterations: 35funcCount: 69algorithm: 'Nelder-Mead simplex direct search'message: 'Optimization terminated:...'

exitflag 的值为 1,这意味着 fminsearch 很可能收敛于局部最小值。

output 结构体显示迭代数。迭代输出中和绘图中也显示此信息。output 结构体还显示函数求值的次数,迭代输出方式会显示该次数,但所选的绘图函数不显示该次数。

基于问题求解

(1)基于求解器求解

clc, clear
f=@(x) x(1)^3-x(2)^3+3*x(1)^2+3*x(2)^2-9*x(1); 
g=@(x) -f(x);
[xy1,z1]=fminunc(f, rand(2,1))  %求极小值点
[xy2,z2]=fminsearch(g,rand(2,1)); %求极大值点
xy2, z2=-z2  %显示极大点及对应的极大值

(2)基于问题求解

clc, clear, prob1=optimproblem;  %最小值问题
x=optimvar('x','LowerBound',-3,'UpperBound',3);
y=optimvar('y','LowerBound',-4,'UpperBound',4);
prob1.Objective=x^3-y^3+3*x^2+3*y^2-9*x;
x0.x=1; x0.y=1;
[sol1,fval1,flag1,out1]=solve(prob1,x0)
prob2=optimproblem('ObjectiveSense','max')
prob2.Objective=x^3-y^3+3*x^2+3*y^2-9*x;
op=optimoptions(@fmincon,'Algorithm','active-set')
[sol2,fval2,flag2,out2]=solve(prob2,x0,'Options',op)

求得的极小值点为 (1,0),极小值为 -5;极大值点为 (-3,2),极大值为 31。

求解有约束极小值

基于求解器求解

非线性规划模型的一般形式为

b 和 beq 是向量,A 和 Aeq 是矩阵,c(x) 和 ceq(x) 是返回向量的函数,f(x) 是返回标量的函数。f(x)、c(x) 和 ceq(x) 可以是非线性函数。

x、lb 和 ub 可以作为向量或矩阵传递。

fmincon(寻找约束非线性多变量函数的最小值)
[x,fval,exitflag,output,lambda,grad,hessian] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)

输入参数:

  • fun 为要计算最小值的函数
  • x0 为初始点,指定为实数向量或实数数组。求解器使用 x0 的大小以及其中的元素数量确定 fun 接受的变量数量和大小。
  • A 为线性不等式约束矩阵,A 表示约束中的线性系数;
  • b 为线性不等式约束向量,b 表示约束中的常向量;
  • Aeq 为线性等式约束矩阵,beq 为线性等式约束向量;
  • lb 为下界,ub 为上界;
  • nonlcon 为非线性约束;
  • options 为 intlinprog 的选项,
  • problem 为封装输入和选项的结构体,
  • lambda 为解处的拉格朗日乘数,
  • grad 为解处的梯度,
  • hessian 为逼近 Hessian 矩阵

输出参数:

  • x 为解
  • fval 为目标函数最优值;
  • exitflag 为算法停止条件,
  • output 为求解过程摘要。

 在非线性约束下求函数的最小值

在边界约束下求 Rosenbrock 函数在圆内最小的点。

fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;

在区域 

$0 \le x(1) \le 0.5$

$0.2 \le x(2) \le 0.8$

 内寻找。

lb = [0,0.2];
ub = [0.5,0.8];

同时在以 [1/3,1/3] 为圆心、半径为 1/3 的圆内寻找。

function [c,ceq] = circlecon(x)
c = (x(1)-1/3)^2 + (x(2)-1/3)^2 - (1/3)^2;
ceq = [];

没有线性约束,因此将这些参数设置为 []

A = [];
b = [];
Aeq = [];
beq = [];

选择一个满足所有约束的初始点。

x0 = [1/4,1/4];

求解。

nonlcon = @circlecon;
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)Local minimum found that satisfies the constraints.Optimization completed because the objective function is non-decreasing in 
feasible directions, to within the value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.x =0.5000    0.2500
基于问题求解

(1)基于求解器求解

clc, clear
fun1 = @(x) sum(x.^2)+8;
[x,y]=fmincon(fun1,rand(3,1),[],[],[],[],zeros(3,1),[],@fun2)function [c,ceq]=fun2(x)
c=[-x(1)^2+x(2)-x(3)^2
x(1)+x(2)^2+x(3)^3-20];  %非线性不等式约束
ceq=[-x(1)-x(2)^2+2
x(2)+2*x(3)^2-3]; %非线性等式约束
end

(2)基于问题求解

clc, clear, prob = optimproblem;
x = optimvar('x',3,'LowerBound',0);
prob.Objective = sum(x.^2)+8;
con1 = [-x(1)^2+x(2)-x(3)^2 <= 0
x(1)+x(2)^2+x(3)^3 <= 20];  %非线性不等式约束
con2 = [-x(1)-x(2)^2+2 == 0x(2)+2*x(3)^2 == 3]; %非线性等式约束
prob.Constraints.con1 = con1;
prob.Constraints.con2 = con2;
x0.x=rand(3,1);  %非线性规划必须赋初值
[sol,fval,flag,out]= solve(prob,x0), sol.x

求得当 x1 = 0.5522, x2 = 1.2033, x3 = 0.9478 时,最小值 y = 10.6511。

 

http://www.mmbaike.com/news/32527.html

相关文章:

  • 旅游资讯网站开发论文千锋教育的it培训怎么样
  • 哪个公司做网站便宜如何引流客源最快的方法
  • 做一个小公司网站多少钱百度指数查询官方下载
  • 网页.网站.主页.网址.域名有什么联系朋友圈广告投放平台
  • 附近的计算机培训班seo怎么优化方案
  • 做老电影网站侵权吗最近的国际新闻
  • php做网站的公司有哪些最近新闻小学生摘抄
  • 中央电视台新闻联播seo优化一般包括
  • 新河网站建设上海搜索排名优化
  • 张家港早晨网站制作新浪网今日乌鲁木齐新闻
  • 网站维护运营优化公司广告精准推广平台
  • 怎样在微信做产品网站东莞网络推广公司
  • 北票网站建设杭州seo公司
  • 镇江网站建设价格营销方式和渠道有哪些
  • 长沙专业做网站公司网站seo排名优化
  • 帮人做钓鱼网站的人荆门今日头条新闻发布
  • 网页游戏广告平台网站建设十大互联网广告公司
  • 制作营销网站模板免费下载优化设计答案大全英语
  • 旅游网站建设公司2021百度最新收录方法
  • 发布外链网站seo的方法有哪些
  • 企业网站设计营销青岛网站建设公司排名
  • 用asp.net做网站网上推广平台有哪些
  • 网站如何做视频的软件2024北京又开始核酸了吗今天
  • wordpress menu css广州seo服务外包
  • 网上商店系统设计软件优化
  • 给千图网等网站做设计赚钱吗西安百度代运营
  • 做推广秒杀网站互联网推广工作好做吗
  • 免费域名注册方式百度快照优化排名
  • 网站干什么的seo快速排名利器
  • 公司网站制作合同市场推广计划书