clc; clear all; close all; x1=-2; x2=2; nx=20; y1=-2; y2=2; ny=20; x = x1 : (x2-x1)/(nx-1) : x2; y = y1 : (y2-y1)/(ny-1) : y2; [X,Y] = meshgrid(x,y); Z=zeros(nx,ny); for i=1:nx for j=1:ny Z(i,j)=banana(x(i),y(j)); end end %Z = X.*Y.*exp(-X.^2-Y.^2); % pointwise multiplication works now because X and Y are matrices figure(1) hold on contour(X,Y,Z,100); plot(0.5*(x1+2),0.5*(x1+2),'-ko') hold off