Help generating plot of Zakharov's function

13 visualizaciones (últimos 30 días)
jay
jay el 2 de Dic. de 2014
Comentada: jay el 2 de Dic. de 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

Respuesta aceptada

Thorsten
Thorsten el 2 de Dic. de 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 comentario
jay
jay el 2 de Dic. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Genetic Algorithm en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by