Help generating plot of Zakharov's function
13 views (last 30 days)
Show older comments
Hi guys,
I have a problem that is probably quite simple but I have been pulling my hair out for a while. I looking for a method of reliably plotting the zakharov function with x constrained to -5 >= x <= 5. Here's what I have so far:
[x,y] = meshgrid(-5:0.1:5,-5:0.1:5);
z = @zakharov;
figure
[C,h] = contour(x,y,z);
I'm having difficulty translating what is in the zakharov.m file to a vectorized form, that produces a grid of the correct size for surf and contour to plot. If possible I would really appreciate a method that I could generalize to multiple dimensions, and use on other built-in optimization functions like schaffers or rastrigins, as I want to try to use them to plot the results from genetic algorithms using these functions as the search space.
Any help on this would be very much appreciated!! Thanks in advance!
Jay
0 Comments
Accepted Answer
Thorsten
on 2 Dec 2014
x = -5:0.1:5; y = x;
for i = 1:numel(x), for j=1:numel(y), Z(j,i) = zakh([x(i) y(j)]); end; end
[X Y] = meshgrid(x, y);
surfl(X,Y,Z)
More Answers (0)
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!