The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.
Become a Premium Member and unlock a new, free course in leading technologies each month.
x = -50 + 100.*rand(50,2);
function f = func(x)
D = 2;
[ps, D] = size(x);
o=-50+100*rand(1,D);
x=x-repmat(o,ps,1);
f = max(abs(x), [], 2);
end
This is how i tried doing it:
cmin = -50;
cmax = 50;
steps = 20;
c = linspace(cmin, cmax, steps); % Create the mesh
[X1, X2] = meshgrid(c, c)
contour(X1,X2,f);
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
x = -50 + 100.*rand(50,2);
This random matrix is going to be passed to the function func like this:eva = func(x)
The function returns an array for vectors which are 50 x 1. I try to plot contour of the resulting eva by doing This: My 2 dimensional map is This [X1, X2] = meshgrid(c, c) as it is shown here:cmin = -50;
cmax = 50;
steps = 20;
c = linspace(cmin, cmax, steps); % Create the mesh
[X1, X2] = meshgrid(c, c)
contour(X1,X2,eva);
The unite of my equal value line is:
steps = 20;
But any time i run this, it tell me that eva, has to be a matrix of atleast 2x2. As it is now it just give a matrix of 50 x 1. I need eva to be atleast 2x2 matrix so that i can plot the contour. I am now seeking for advice how to do this. Is there a way i can plot the contour? Any suggestion?
M = 50;
n = 2;
x = -50 + 100.*rand(M,n);
cmin = -M;
cmax = M;
ngrid = 5.05;
x = cmin:ngrid:cmax;
y = cmin:ngrid:cmax;
o = -50+100*rand(1,n);
y = y - repmat(o,1,10);
x = x - repmat(o,1,10);
f = arrayfun(@tteee1,x);
figure;
contour(x,y,f);
figure;
surfc(x, y,f);
title(sprintf('The Surface and contour Plot'))
:function fit = tteee1(x)
D = 2;
[ps, D] = size(x);
o=-50+100*rand(1,D);
x=x-repmat(o,ps,1);
fit = max(abs(x), [], 2);
end
??? Error using ==> contour at 73
Z must be size 2x2 or greater.
Error in ==> tteee at 20
contour(x,y,f);
data = 20*rand([10,10])
figure;
contour(data);
cmin = -M;
cmax = M;
steps = 20;
c = linspace(cmin, cmax, steps); % Create the mesh
[x, y] = meshgrid(c, c); % Create the grid
o=-50+100*rand(1,n);
c = c - repmat(o,1,10);
f = arrayfun(@tteee1,x);
figure,
contour(x,y,f);
figure,
surfc(x, y,f);
function f= tteee1(x)
D = 2;
[ps, D] = size(x);
o=-50+100*rand(1,D);
x=x-repmat(o,ps,1);
f = max(abs(x), [], 2);
end
for x = 1:20
for y = 1:20
hilbert(x, y) = 1/(x+y -1);
end
end
This is an example from the Matlab documentation.
cmin = -M;
cmax = M;
steps = 20;
c = linspace(cmin, cmax, steps); % Create the mesh
[x, y] = meshgrid(c, c); % Create the grid
%o=-50+100*rand(1,n);
%c = c - repmat(o,1,10);
for I=1:length(x)
for J=1:length(y)
o=-50+100*rand(1,2);
x=x-repmat(o,20,10);
f = max(abs(x), [], 2);
end
end
figure,
contour(x,y,f);
figure,
surfc(x, y,f);
Z must be size 2x2 or greater
Are you really trying to do something with Genetic Algorithms and the Schwefel function?Yes, i am actually try to implement Estimation of Distribution Algorithm (EDA) in Evolutionary Computation to understand it. I am trying to test it on Benchmark functions in 2d and i am having trouble with plotting contour of some of them, and Schwefel function is one of them.
SWxlimits = [-100 100];
SWbias = [20 -20];
SWdx = (SWxlimits(2) - SWxlimits(1)) / 100;
SWN = floor((SWxlimits(2) - SWxlimits(1)) / SWdx) + 1;
Schwefel221objShifted = zeros(SWN, SWN);
SWi = 0;
for SWx = SWxlimits(1) : SWdx : SWxlimits(2)
SWi = SWi + 1;
SWk = 0;
for SWy = SWxlimits(1) : SWdx : SWxlimits(2)
SWk = SWk + 1;
Schwefel221objShifted(SWi,SWk) = max(abs(SWx-SWbias(1)), abs(SWy-SWbias(2)));
end
end
[SWx, SWy] = meshgrid(SWxlimits(1) : SWdx : SWxlimits(2));
figure;
contour(SWx,SWy,Schwefel221objShifted);
figure;
figure;
surfc(SWx,SWy,Schwefel221objShifted);
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.