How to plot rastrigin function in matlab
61 views (last 30 days)
I'm trying to plot rastrigin function this way
clear; clc; close all;
limits = repmat([-5 5], 2, 1);
[X,Y] = meshgrid(linspace(limits(1,1),limits(1,2),100),...
Z = reshape(rastrigin([X(:)'; Y(:)']), 100, 100);
axis([-5 5 -5 5 0 90]);
function [y] = rastrigin(x)
d = length(x);
sq = x.^2;
y = 10*d + sum(sq - 10*cos(2*pi*x));
But I'm getting empty figure
dpb on 13 Nov 2016
Your scaling seems to be out of whack--adding 10+length(x) is creating a Z of
>> [min(Z(:)) max(Z(:))]
Hence your axis command puts the Z axis range quite a long distance below where the data values are.
It appears from the functional definition, the offset factor you're looking for would be 20; 2X the scale factor of the cosine term. If I do that and then
get an interesting figure, indeed. Hadn't heard of the rastrigin function...