algorithm - Need Help in Contour Plot in Matlab -
i trying plot contour of shifted schwefel problem function keep having error: z must size 2x2 or greater. have searched on forum , information have helped little, not fix above error. information got forum lead me trying code:
min = -50; max = 50; steps = 20; c = linspace(min, max, steps); % create mesh [x, y] = meshgrid(c, c); % create grid %o=-50+100*rand(1,2); %c = c - repmat(o,1,10); i=1:length(x) 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);
now have error z, the value of f atleast 2x2 or greater. know f taking 1 input , therefore output one. tried having in nested loops, still giving me array of vectors not matrix of atleast 2x2. if input two, problem fine, problem is, 1 input. know how can make "f" output matrix of atleast 2x2 can plot z of contour?
there few things note:
1.) jacob robbins pointed out correctly in comment, should avoid using names matlab functions variable names (in case min
, max
). 1 easy way this, use upper case letters variable names.
2.) correct in saying f
is 1 output (though one output in case not single number, vector). is, because don't assign indexing within loop.
3.) yes, both contour
, surfc
need @ least 2x2
- because plot information on grid, @ least 2x2
in nature.
4.) in particular case, 2 loops may not necessary. seem manipulating x
-vector , grid regular. hence might want try loop:
for i=1:length(x) o=-50+100*rand(1,2); x=x-repmat(o,20,10); f(:,i) = max(abs(x), [], 2); end
now, f
of size 20x20
, corresponds x
- , y
-grid. also, contour
, surfc
command produce plots.
5.) 1 last comment: output of function , results of web-search "shifted schwefel function" different. question if implementation of shifted schwefel function correct, should asked new question.
Comments
Post a Comment