当前位置:网站首页>MATLB|And her ups and downs and finally reached the peak of life [Romantic Journey]
MATLB|And her ups and downs and finally reached the peak of life [Romantic Journey]
2022-08-10 01:28:00 【Electrical Engineering Workshop】
️️️️️️
Have the same mind as the sea,To have a life like the sea;Has the tranquility of the sea,To be able to withstand the turbulent waves.Be like a sea,有跌宕起伏,There was placidity.

欢迎来到本博客️️️
博主优势:博客内容尽量做到思维缜密,逻辑清晰,为了方便读者,博主专门做了一个专栏目录,整个专栏只放了一篇文章,足见我对其重视程度:博主专栏目录.做到极度细致,方便大家进行学习!亲民!!!还有我开了一个专栏给女朋友的,很浪漫的喔,代码学累的时候去瞧一瞧,看一看:女朋友的浪漫邂逅.有问题可以私密博主,博主看到会在第一时间回复.
欢迎您的到来
个人主页:科研室
所有代码目录:电气工程科研社
【现在公众号名字改为:荔枝科研社】
本文目录如下:️️️
目录

Nice running result

Matlab代码
function [] = LocalMinimaSuffring()
close all; clear all;
global history
history = [];
% *************Peak function****************
dx = 1/8;
[x,y] = meshgrid(-3:dx:3);
z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ...
- 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ...
- 1/3*exp(-(x+1).^2 - y.^2);
% Self demonstration
surfc(x,y,z)
axis('tight')
xlabel('x'), ylabel('y'), title('峰值')
%% ******************开始********************
x0 = [-3 -3];
y0 = peaksObj(x0);
hold on
plot3(x0(1),x0(2),-10,'gs','lineWidth',2,'MarkerSize',10);
plot3(x0(1),x0(2),y0,'gs','lineWidth',2,'MarkerSize',10);
% [c,ceq] = peaksCon(x0)
options = optimset('Display','iter','OutputFcn',@peaksOutputFcn);
x = fmincon(@peaksObj,x0,[],[],[],[],[],[],@peaksCon,options)
plot3(history(:,1),history(:,2),(-10)*ones(size(history,1)),'-r.','lineWidth',1,'MarkerSize',15)
plot3(history(:,1),history(:,2),history(:,3),'-r.','lineWidth',1,'MarkerSize',15)
plot3(history(end,1),history(end,2),-10,'r*','lineWidth',2,'MarkerSize',10)
plot3(history(end,1),history(end,2),history(end,3),'r*','lineWidth',2,'MarkerSize',10)
%% ******************x0 = [3 -2];********************
history = [];
x0 = [3 -2];
hold on
plot3(x0(1),x0(2),-10,'go','lineWidth',2,'MarkerSize',10);
plot3(x0(1),x0(2),y0,'go','lineWidth',2,'MarkerSize',10);
options = optimset('Display','iter','OutputFcn',@peaksOutputFcn);
x = fmincon(@peaksObj,x0,[],[],[],[],[],[],@peaksCon,options)
plot3(history(:,1),history(:,2),(-10)*ones(size(history,1)),'-r.','lineWidth',1,'MarkerSize',15)
plot3(history(:,1),history(:,2),history(:,3),'-r.','lineWidth',1,'MarkerSize',15)
plot3(history(end,1),history(end,2),-10,'r*','lineWidth',2,'MarkerSize',10)
plot3(history(end,1),history(end,2),history(end,3),'r*','lineWidth',2,'MarkerSize',10)
box on
end
function stop = peaksOutputFcn(x, optimValues,state)
stop =false;
% hold on;
% plot3(x(1),x(2),-10,'*');
record(x,optimValues.fval);
end
function []=record(x,y)
global history
history=[history;[x,y]]
end
function f = peaksObj(x)
%PEAKSOBJ casts PEAKS function to a form accepted by optimization solvers.
% PEAKSOBJ(X) calls PEAKS for use as an objective function for an
% optimization solver. X must conform to a M x 2 or N x 2 array to be
% valid input.
%
% Syntax
% f = peaksObj(x)
%
% Example
% x = [ -3:1:3; -3:1:3]
% f = peaksObj(x)
%
% See also peaks
% Check x size to pass data correctly to PEAKS
[m,n] = size(x);
if (m*n) < 2
error('peaksObj:inputMissing','Not enough inputs');
elseif (m*n) > 2 && (min(m,n) == 1) || (min(m,n) > 2)
error('peaksObj:inputError','Input must have dimension m x 2');
elseif n ~= 2
x = x';
end
% Objective function
f = peaks(x(:,1),x(:,2));
end
function [c,ceq] = peaksCon(x)
%PEAKSCON Constraint function for optimization with PEAKSOBJ
% PEAKSCON(X) is the constraint function for use with PEAKSOBJ. X is of
% size M x 2 or 2 x N.
%
% Sytnax
% [c,ceq] = peaksCon(x)
%
% See also peaksobj, peaks
% Check x size to pass data correctly to constraint definition
[m,n] = size(x);
if (m*n) < 2
error('peaksObj:inputMissing','Not enough inputs');
elseif (m*n) > 2 && (min(m,n) == 1) || (min(m,n) > 2)
error('peaksObj:inputError','Input must have dimension m x 2');
elseif n ~= 2
x = x';
end
% Set plot function to plot constraint boundary
try
mypref = 'peaksNonlinearPlot';
if ~ispref(mypref)
addpref(mypref,'doplot',true);
else
setpref(mypref,'doplot',true);
end
catch
end
% Define nonlinear equality constraint
ceq = [];
% Define nonlinear inequality constraint
% x1^2 + x^2 <= 3^2
c = x(:,1).^2 + x(:,2).^2 - 9;
% fmincon accepted input form is ceq <= 0
end边栏推荐
猜你喜欢

KingbaseGIS Jin Cang database using manual (6.3. Geometric object creation function)

【集训DAY3】石油储备计划【树形DP】

Golden Warehouse Database KingbaseGIS User Manual (6.4. Geometry Object Access Function)

【Infiltration tool】Browser data export tool

【云原生】Kubernetes编排工具精讲

今日睡眠质量记录61分

MATLB|和她跌宕起伏最终到达人生之峰【浪漫旅途】

【SSL集训DAY3】控制棋盘【二分图匹配】

Creo5.0 introductory tutorial free material

信息系统项目管理师核心考点(六十四)信息安全基础知识重要概念
随机推荐
考柏的感慨
JS基础笔记-关于对象
安全知识培训——消防安全
In-depth understanding of multithreading (Part 1)
【集训DAY3】阶乘【数学】
Cmake 用法记录
拒绝“重复造轮子”,百度EasyDL让你玩转AI定制开发
redis分布式锁代码示例
【诗歌】爱你就像爱生命
【集训DAY3】石油储备计划【树形DP】
Jpa 查询view or 无主键的table
ES6 从入门到精通 # 15:生成器 Generator 的用法
dlopen failed: library “libtaml.so“ not found
【Infiltration tool】Browser data export tool
领跑政务云,连续五年中国第一
hql语言
mysql无法远程连接 Can‘t connect to MySQL server on ‘xxx.xxx.xxx.xxx‘ (10060 “Unknown error“)
生成树和交换的总结
Redis-基本介绍/linux下环境配置/配置文件
Travel with Shengteng: See all the AI attractions in Jinling City in one day
