How to plot $f(x,y)=\dfrac{1}{x^4+2x^2y^2+y^4+1}$ in MATLAB?

77 Views Asked by At

How do I plot or how does the following function look?

$$f(x,y)=\frac{1}{x^4+2x^2y^2+y^4+1}$$

I could rewrite this $$\frac{1}{r^4+1}.$$

2

There are 2 best solutions below

0
On

Have you tried using mesh/meshgrid functions? In your case it should look like this

[x y]=meshgrid(from:step:to);
z=1./(x.^4+2x.^2y.^2+y.^4+1);
mesh(x,y,z);
0
On

There is the function called fsurf() to plot the surface. The usage is:

f1 = @(x,y) 1/(x^4+2*x^2*y^2+y^4+1);
fsurf(f1,[-5 5 -5 5])

It generates the graph show here -- Output of fsurf(). The same can also be done using mesh() as mentioned by @polko14.

[x, y]=meshgrid(-5:0.1:5);
z=1./(x.^4+2*x.^2.*y.^2+y.^4+1);
mesh(x,y,z);

which generates the same plot -- Output of mesh().