Ackley Function 3D plot

34 visualizaciones (últimos 30 días)
bhargav mehar
bhargav mehar el 14 de Abr. de 2021
Comentada: bhargav mehar el 14 de Abr. de 2021
Ackley function has the formula of
I have been trying to plot the same but the function is not running. Please help me to understand how to plot. Thanks in advance
function [out]=ackley(in)
x=in;
e=exp(1);
out = (20 + e-20*exp(-0.2*sqrt((1/2).*sum(x.^2,2)))-exp((1/2).*sum(cos(2*pi*x),2)));
return
x = -3:3;
y = -3:3;
[X,Y] = meshgrid(x,y);
in = [X(:), Y(:)];
out = ackley(in);
Z = reshape(out, size(X));
surf(X, Y, Z);

Respuesta aceptada

Chad Greene
Chad Greene el 14 de Abr. de 2021
It looks like the code stops at the line that says return. Try putting the function at the bottom of the script and ending it with the word end. Like this:
(Below I have increased the spatial resolution by doing x and y steps of 0.01. I've also turned on the lighting to make it look more 3D.)
x = -3:.01:3;
y = -3:.01:3;
[X,Y] = meshgrid(x,y);
in = [X(:), Y(:)];
out = ackley(in);
Z = reshape(out, size(X));
surf(X, Y, Z);
shading interp
camlight
material dull
function [out]=ackley(in)
x=in;
e=exp(1);
out = (20 + e-20*exp(-0.2*sqrt((1/2).*sum(x.^2,2)))-exp((1/2).*sum(cos(2*pi*x),2)));
end
  1 comentario
bhargav mehar
bhargav mehar el 14 de Abr. de 2021
Thank you so much!! It worked like a charm. :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Financial Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by