# matlab

```MATLAB
Creating a Surface Plot
Alan Harris
Liz Kuhn
Amanda Williams
Jessica Warrington
What is a Surface Plot?
A
surface plot is a graph of a threedimensional function
– Any function of the type z=f(x,y)
 Today,
we will create a simple
hyperbolic paraboloid of form
z=x^2-y^2
What Should This Look Like?
Starting MATLAB
Double Click
on the
MATLAB
Icon
 Wait until
the
Command
Window

Creating the Domain
 This
is the area in Cartesian space
over which the function will be
graphed
 Enter the following commands in the
Command Window:
– x = linspace(-5,5,51);
– y = linspace(-5,5,51);
 The
domain is x[-5,5];y[-5,5]
 The domain is divided into 51 equidistant
points
Creating the Mesh
The last two commands made a 51
element x array and a 51 element y array
 Now, we are creating two 51 by 51
matrices, one for x, one for y

1 2 3
– If x was [1,2,3], this makes 1 2 3


1 2 3

Enter into the Command Window:
– [X,Y] = meshgrid(x,y);
Using the Mesh
 Now,
use the X and Y matrices to
create the function
 Enter into the Command Window:
– Z = X.^2-Y.^2 ;
 The
“.^” means to square each individual
element
 The “-” follows normal matrix subtraction
 This creates a 51 by 51 matrix of z values
Plotting the Function
 This
is where MATLAB does all the
work for you
 Enter into the Command Window:
– surf(X,Y,Z)
 This
creates a new window in which your
function is graphed