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

📄 matlab 多维变量的优化问题.txt

📁 MATLAB绘制出权值wv和阀值bv确定的误差曲面
💻 TXT
字号:
多维变量的优化问题2007/06/02 23:56求4维Corana函数在区间[-10000 10000]内的极小值
function [val] = coranaEval(sol)
numv = size(sol,2);
x=sol(1:numv);
d0=[1 1000 10 100 1 10 100 1000 1 10];
d=d0(1:numv);
c=0.15;
s=.2*ones(1,numv);
t=0.05*ones(1,numv);
bk = s.*(round(x./s));
dev= (abs(bk-x)<t) & (bk~=0);
z=c*((bk+sign(bk).*t).^2).*d;
y=x.^2.*d;
val = sum((dev.*z) + ((~dev).*y));
function [sol,val] = coranaMin(sol,options)
numVar=size(sol,2)-1;
val = coranaEval(sol(1:numVar));
val = -val;
>>
clf;
figure(gcf);
echo on
clc
% This demonstration show the use of the genetic toolbox to optimize a
% multi-dimensional non-convex function.
% The function is coded in the coranaEval.m file
pause %Strike any key to examine coranaEval
clc
type coranaEval.m
pause %Strike any key to continue
clc
%This function is basically a n dimensional parabola with rectangular
%pockets removed. Let's take a look at the function in 2-dimensions
%This may take a couple of minutes...
echo off    
i=0;
a=-0.5:0.02:0.5;
for x=a
   i=i+1; j=0;
   for y=a
     j=j+1;
     z(i,j)=coranaEval([x y]);
   end
end
echo on
%Done!
%First let's look at it in each dimension independently
clf
plot(z(:,1)) %Plot a slice of the function in x max 250.25
%Notice the range is [250.0-250.25]
pause %Strike any key to continue
clf
plot(z(1,:)) %Plot a slice of the function in y 
%Notice the range is [0-250]
pause %Strike any key to continue
mesh(a,a,z);
view(30,60);
grid;
%Remember the deviation in y is 1000 times that of x.
pause %Strike any key to continue
clc
%Lets minimize this function in 4 dimensions between [-10,000 10,000].
%The ga is set up to maximize only.   Minimization of f(x) is equivalent to
%maximizing -f(x), so we use the negative of the Corana function.
type coranaMin.m
pause %Any key to continue
clc
%First set up the bounds
bounds = ones(4,1)*[-10000 10000];
%Now lets optimize
%This may take some time...
[x,endPop,bestSols,trace]=ga(bounds,'coranaMin');
%Done!
pause %Any key to continue
clc
%The first return is the optimal [x1 x2 x3 x4 val]
x
%Lets take a look at the performance of the ga during the run
plot(trace(:,1),trace(:,3),'y-')
hold on
plot(trace(:,1),trace(:,2),'r-')
xlabel('Generation'); ylabel('Fittness');
%The red line is a track of the best solution, the yellow is a track of the
%average of the population
pause %Any key to continue
clc
%The first return is the optimal [x1 x2 x3 x4 val]
x
x =
   -33.7847     0.1716    -0.4250     0.2218 -182.4896
 

⌨️ 快捷键说明

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