Hi why am i getting this error?
x = linspace(-1,1,20);
y = linspace(-2,2,40);
z = (1.+sin(pi.*x)).*((3.+cos(1.065.*y)).^2).*exp(-x.^2 -(y.^2)./4);
??? Error using ==> minus Matrix dimensions must agree.
Because x
and y
are not the same size. What you likely want to use here is meshgrid
.
The code would be something like:
[x,y] = meshgrid(linspace(-1,1,20),linspace(-2,2,40));
z = (1.+sin(pi.*x)).*((3.+cos(1.065.*y)).^2).*exp(-x.^2 -(y.^2)./4);
Then you can visualize like:
surf(x,y,z)
And get stuff like this: