0

I am trying to create a 3D plot of f(x,y)=xsin(xy)exp(-(x+y)/10) uisng the surf command. My code is below:

x=linspace(-5,5,400);
y=linspace(-3,3,400);
[X,Y]=meshgrid(x,y);
Z=x.*sin(x.*y).*exp(-(x+y)/10);
surf(X,Y,Z);
shading interp;

The error Z must be a matrix, not a scalar or vector is being displayed. What have I done wrong?

  • 1
    You probably want `Z=X.*sin(X.*Y).*exp(-(X+Y)/10);`. With your current code you generate `Z` as a vector – Luis Mendo Feb 23 '20 at 03:31
  • Does this answer your question? [How can I plot a function with two variables in octave or matlab?](https://stackoverflow.com/questions/16868074/how-can-i-plot-a-function-with-two-variables-in-octave-or-matlab) – SecretAgentMan Feb 24 '20 at 13:50

0 Answers0