MATLAB: How can we plot this function as 3d with matlab
3d plotsplotplottingsurf
how can we plot this fucntion as 3d with matlab? I tried surf and ezplot to plot function. but they didnt work. thanks for help.
Best Answer
Aww, cute.
The reason you can't usesurf orezplot is that these are not designed for this kind of equation. To usesurf you need to have a surface defined as z = f(x,y). You have g(x,y,z) = 0. If you could rearrange that into z = f(x,y), you could usesurf, but the equation you have doesn't really allow that.
So... instead, go back to the definition of the surface as g(x,y,z) = 0. Think of this as a particular isosurface of the function g(x,y,z) (with isosurface value of 0).
To make a surface in MATLAB from that kind of setup, you need (surprise, surprise)isosurface. Look in the documentation at the examples forisosurface. They will guide you through the visualization.
The one thing you need that isn't in theisosurface doc is to create the data to plot. (The examples do[x,y,z,v] = flow; which creates the data from a canned routine for a specific example.) So:
You need to create 3 3-D arrays for x, y, and z, in the given range -- hint:linspace andmeshgrid.
Then you need to evaluate the function g(x,y,z) at each of those x, y, z locations: V = (X.^2+9*Y.^2/4+Z.^2-1).^3 - X.^2.*Z.^3 (etc)
Now you have the data, you can plot, using the examples in theisosurface documentation.
Best Answer