Which line of your code is at 89? Which is at 73?
What is Z?
??? Error using ==> sphere Too many input arguments.
Error in ==>sphereplotting at 89
Z = sphere(X1,X2);
function ph = sphere(x)
ph = sum(x.*x, 2);
end
??? Error using ==> contour at 73
Z must be size 2x2 or greater.
cmin = -25;
cmax = 25;
ngrid = 25;
cvals = linspace(cmin, cmax, ngrid); % Create the mesh
[X1, X2] = meshgrid(cvals, cvals); % Create the grid
% k=1,l=2;
Z = sphere(X1,X2);
figure;
contour(X1, X2, Z);
M = 100; % population size
n = 2;
pop = 0 + 1.*randn(M,n);
[popSize d] = size(pop);
G = 25; % number of generations for the fitness evaluation function
Max_F = 1000; % maximal number of FEs
options.optmType = 'max';
y = zeros(1,G);
for i =1:G
eval = sphere(pop); % fitness evaluation of the initial population.
% Setting Criteria for selecting N(<=M)
if ~isfield(options, 'optmType')
error('Please provide optimisation type {min, max}');
end
% define best population size
if isfield(options, 'topSize')
topSize = options.topSize;
if topSize > popSize
disp('Warning: topSize is larger than popSize, will use, popSize/10');
topSize = 0.25 * popSize;
options.topSize = topSize;
end
else
topSize = 0.25 * popSize;
options.topSize = topSize;
end
% all initial pop are top_x
top_x = pop;
% Criteria for selecting top 'topSize' individuals based on fitness
% values(eval)
if strcmp(options.optmType, 'min')
[void, b] = sort(eval, 'descend'); % maximising
else
[void, b] = sort(eval, 'ascend'); % minimising
end
top_x = pop(b(1:options.topSize),:); % select top individuals
optm_x = pop(b(1),:); % save optimal parameter
fv = eval(b(1)); % save optimal func. value
mu = mean(top_x); % mean vector calculation
Sigma = cov(top_x); % Covariance calculation
pop = mvnrnd(mu,Sigma,M); % Calculate joint probability distribution of selected individuals(sampling)
dstring = [num2str(M), ' samples are generated.'];
subplot(1,2,1);
y(i) = sphere(optm_x);
plot(y(1:i));
xlabel('Generations')
ylabel(' Best Individuals')
title(sprintf('At the some Generations'))
%axis('equal');
cmin = -25;
cmax = 25;
ngrid = 25;
cvals = linspace(cmin, cmax, ngrid); % Create the mesh
[X1, X2] = meshgrid(cvals, cvals); % Create the grid
Z = sphere(X1);
subplot(1,2,2);
contour(X1, X2, Z);
end
eval = sphere(pop); % fitness evaluation of the initial population.
Z = arrayfun(@sphere, X1);
The surf & Plot3 plots show a parabola, but the contour plot shows only vertical lines, not contours. I don't know why? contour(X1, X2, Z);
shows the vertical lines not contours, why?surf(X1, X2, Z); and Plot3(X1, X2, Z);
show parabola which is reasonable.arrayfun
?
function ph = sphere(x)
ph = sum(x.*x,2);
end
Z = arrayfun(@sphere, X1);
eval = sphere(pop);
contour(X1, X2, Z);
Is showing vertical line, not contour line. This is not how it should be. How can i fix this?
K= 4
for l = 1 : K
contour(X,Y,ph);
hold on
plot(bestId, 'rx');
end
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
Quadratic Equation | 5 | 66 | |
Specific format | 21 | 182 | |
Hashing Algorithm | 5 | 53 | |
Problem to open Excel file | 15 | 97 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
13 Experts available now in Live!