Help generating plot of Zakharov's function

12 vues (au cours des 30 derniers jours)
jay
jay le 2 Déc 2014
Commenté : jay le 2 Déc 2014
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

Réponse acceptée

Thorsten
Thorsten le 2 Déc 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)
  1 commentaire
jay
jay le 2 Déc 2014
Hi Thorsten
This works great! I've been able to generalise it to other functions too. Thanks for your answer, elegantly concise and exactly what I was looking for. Big thumbs up!
Thanks Jay

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by