Graphing a function f(x,y) on a restricted set of values for (x,y)

576 Views Asked by At

I'm having a hard time with this certain problem.

Suppose that $S=\{(x,y): x^2 + y^2\leq 4\}$ and define $f:S\rightarrow\mathbb{R}$ as $f(x,y)=-x-2y-2y^2+cos(x\pi /4)$.

How can we produce a (3d) plot, in MATLAB or Mathematica, that shows whether this function is convex or concave (or neither)?

Thanks in advance for your help.

2

There are 2 best solutions below

2
On

Here is the plot using wolfram alpha over $[0,2]^2$:

Clearly looks concave.

1
On

In Matlab this can be done by combining meshgrid and pol2cart:

th = linspace(0,2*pi,40);
r = linspace(0,4,20);
[TH,R] = meshgrid(th,r);
[X,Y] = pol2cart(TH,R);
Z = -X-2*Y-2*Y.^2+cos(X*pi/4);
surf(X,Y,Z)
xlabel('x')
ylabel('y')
zlabel('z')