Planes in Matlab
Like the line in space, a plane is completely determined by a minimal set of information. Imagine a point in space. There are an infinite number of planes that pass through this given point. However, there is only one plane that passes through this point that is orthogonal to a given vector.
Consider the plane shown in Figure 1. Note that the plane contains a given point `P_0(x_0,y_0, z_0)` and is orthogonal to a given vector `\vec n = langle A, B,C rangle`.
A plane through `P_0` orthogonal to `\vec n`.
Let `P(x,y, z)` be an arbitrary point in the plane. The key to finding the equation of the plane is to note that the vectors `vec(P_0P)` and `vec n` are orthogonal. Therefore,
`vec (P_0P) cdot vec n = 0`.
is the equation of the plane. This is the key idea, the rest is simple arithmetic.
$\begin{eqnarray} \langle x - x_0,y - y_0, z - z_0 \rangle \cdot \langle A, B,C \rangle &=& 0\\ A(x - x_0) + B(y - y_0) + C(z - z_0) &=& 0\\ Ax + By + Cz - (Ax_0 + By_0 + Cz_0) &=& 0 \end{eqnarray}$
Letting `D = -Ax_0 - By_0 - Cz_0`, the equation of the plane is
`Ax + By + Cz + D = 0.`
Many students of multivariable calculus find it useful to memorize this equation of the plane. Indeed, it is handy for quick solutions. For example, suppose that we wish to find the equation of the plane passing through `(1, 1, 1)` and orthogonal to the vector `vec n =langle 1, 2, 3 rangle`. A typical approach is to substitute 1, 2, and 3, for `A`, `B`, and `C`, getting `x + 2y + 3z + D = 0`. Now, use the point `(1, 1, 1)` to find the value of `D` with this calculation:
$\begin{eqnarray} x + 2y + 3z + D &=& 0\\ 1 + 2(1) + 3(1) + D &=& 0\\ D &=& -6.\end{eqnarray}$
Therefore, the equation of the plane is `x +2y +3z -6 = 0`. However, this computation does nothing to strengthen our knowledge of vector geometry, so I'll avoid this approach like the plague. I prefer to work with the image shown in Figure 1 and the resulting equation `vec(P_0P) cdot vec n=0`.
However, I do find it useful to remember that the vector normal to the plane `Ax + By + Cy + D = 0` is `vec n =langle A, B,C rangle`. For example, a normal vector to the plane `2x - 3y + 5z - 11 = 0` is `langle 2,-3, 5 rangle`. I will use this often.
Surfaces in Matlab
In single variable calculus, we studied functions that mapped the real numbers into the real numbers. In symbols, `f : R to R`. In the plane `R^2`, the graph of this function `f` is defined as follows.
Suppose that `f : R to R`. Then the graph of `f` is
`{(x, f (x)) : x ` is in Domain of `f }`.
That is, the graph of `f` is the set of all ordered pairs that satisfy the equation of `f` . For example, suppose that `f : R to R` is defined by the equation `f (x) = x^2`. An easy calculation shows that `f (2) = 4`. Therefore, the ordered pair `(2, 4)` lies on the graph of `f`. Now, suppose that we have a function that maps elements in the plane onto the real line. That is, `f : R^2 to R`. Then the graph of `f` lies in 3-space (`R^3`) and is defined as follows.
Suppose that `f : R^2 to R`. Then the graph of `f` is
`{(x,y, f (x,y)) : (x,y)` is in the Domain of `f }`,
Thus, the graph of `f` is the set of all ordered triples that satisfy the equation of `f` . For example, suppose that `f : R2 to R` is defined by the equation `f (x,y) = x^2 + y^2`. Then an easy calculation shows that `f (2, 1) = 5`. Therefore, `(2, 1, 5)` is an ordered triple that lies on the graph of `f` . This point is shown in Figure 2.
Point `(2,1,5)` is on the graph of `f`.
To plot the graph of `f (x) = x^2` in the plane, we begin by making a table of points that satisfy the equation, as shown in Table 1.
| `x` | `-3` | `-2` | `-1` | `0` | `1` | `2` | `3` |
| `f(x)=x^2` | `9` | `4` | `1` | `0` | `1` | `4` | `9` |
A table of points satisfying `f(x)=x^2`.
However, if `f (x,y) = x^2+y^2`, the domain of `f` lies in `R^2`. Thus, for each ordered pair `(x,y)`, our function computes an output `z = f (x,y)`. It is the ordered triple `(x,y, z)` that must be plotted. We must come up with a new strategy for creating a table of points that satisfy the equation `f (x,y) = x^2 + y^2`. Matlab accomplishes this with the meshgrid command.
>> [X,Y]=meshgrid([1,2,3,4,5])
X =
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
Y =
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
This rather cryptic output warrants extensive explanation. Actually, the output is easily understood if one superimposes the matrix Y onto the matrix X to obtain a grid of ordered pairs.
| `(1,1)` | `(2,1)` | `(3,1)` | `(4,1)` | `(5,1)` |
| `(1,2)` | `(2,2)` | `(3,2)` | `(4,2)` | `(5,2)` |
| `(1,3)` | `(2,3)` | `(3,3)` | `(4,3)` | `(5,3)` |
| `(1,4)` | `(2,4)` | `(3,4)` | `(4,4)` | `(5,4)` |
| `(1,5)` | `(2,5)` | `(3,5)` | `(4,5)` | `(5,5)` |
Interpreting the output of meshgrid.
Therefore, Table 2 contains a set of points in the plane that we will substitute into the function `f (x,y) = x^2 +y^2`. Matlab's array smart operators make this an easy proposition.
>> Z=X.^2+Y.^2
Z =
2 5 10 17 26
5 8 13 20 29
10 13 18 25 34
17 20 25 32 41
26 29 34 41 50
The alert reader will want use their calculator (mental calculations are also good) to check that these points actually satisfy the equation `f (x,y) = x^2 +y^2`. It is now an easy task to plot the surface to which these points belong. The following command was used to produce the image in Figure 3.
>> mesh(X,Y,Z)

Plotting the surface `f(x,y)=x^2+y^2`.
Recall how Matlab's plot command was used to draw the graphs of functions.
>> x=linspace(0,2*pi); >> y=sin(2*x); >> plot(x,y)
This set of commands would plot the points in the vectors x and y, then line segments were used to connect consecutive points. If you plotted enough points, then the plot took on the shape of a smooth curve. Too few points and your plot had a "jagged" look.
When Matlab plots a surface, a similar thing occurs. Matlab plots the points, then neighboring points are connected with segments. The surface takes on the appearance of a mesh, where each set of four neighboring points seemed to be joined with small quadrilaterals. Again, if you plot too few points, the surface takes on a "jagged" look and feel. To draw a smoother surface, plot more points. The following commands were used to draw the image in Figure 4.
>> [X,Y]=meshgrid(1:.2:5); >> Z=X.^2+Y.^2; >> mesh(X,Y,Z)

A smoother plot of the surface `f(x,y)=x^2+y^2`.
A Plane is a Surface
But this activity is about plotting lines and planes, so let's use our newly found knowledge of surface plotting in Matlab. After all, a plane is an example of a surface.
Plot the plane that passes through the point `(-3, 4,-2)` that is orthogonal to the vector `vec n =langle 1, 2, 3 rangle`.
Solution. Sketch the plane, the given point, and the normal vector.
A plane through `(-3,4,-3)` orthogonal to `langle 1,2,3 rangle`.
The equation of the plane is
$\begin{eqnarray} \vec{P_0P}\cdot \vec n &=& 0\\ \langle x + 3,y - 4, z + 2 \rangle\cdot \langle 1, 2, 3 \rangle &=& 0\\ 1(x + 3) + 2(y - 4) + 3(z + 2) &=& 0\\ x + 2y + 3z + 1 &=& 0. \end{eqnarray}$
Solve this last equation for `z`.
`z =frac(-1 - x - 2y)(3)`
Set up a grid of points. We will let `-5 le x le 5` and `-3 le y le 3`.
>> x=-5:5; y=-3:3; >> [X,Y]=meshgrid(x,y);
Calculate the z-value for each ordered pair `(x,y)`.
>> Z=(-1-X-2*Y)/3;
Finally, plot the plane. The following code produces the image in Figure 5.
>> mesh(X,Y,Z)
>> xlabel('x-axis')
>> ylabel('y-axis')
>> zlabel('z-axis')
>> title('The graph of x + 2y + 3z + 1 = 0')
>> axis tight
>> grid on
>> box on
>> view([150,30])

The graph of `x+2y+3z+1=0` fpr `-5 le x le 5` and `-3 le y le 3`.
Adding a grid and turning "on the box" offers some depth to the image. The view command rotates the graph into the standard `xyz` frame used to plot three dimensional surfaces on our homework.
Matlab Files
Although the following file features advanced use of Matlab, we include it here for those interested in discovering how we generated the images for this activity. You can download the Matlab file at the following link. Download the file to a directory or folder on your system.
The file planes.m is designed to be run in "cell mode." Open the file planes.m in the Matlab editor, then enable cell mode from the Cell Menu. After that, use the entries on the Cell Menu or the icons on the toolbar to execute the code in the cells provided in the file. There are options for executing both single and multiple cells. After executing a cell, examine the contents of your folder and note that a PNG file was generated by executing the cell.
Exercises
Include the following with each exercise:
- Include all pencil and paper work required to produce the required equations.
- Include a printout of your final image.
- Include a printout of the M-code used to produce your final image.
- Sketch the plane passing through the point `(2, 3,-1)` that is orthogonal to the vector `langle 1,-1, 3 rangle`.
- Sketch the plane passing through the point `(1, 2, 3)` that is perpendicular to the line defined by
`frac(x - 1)(2)=frac(y + 1)(-3)=frac(z - 2)(4)`.
- Sketch the plane passing through the points `(0, 0, 0)`, `(1, 2,-1)`, and `(3, 0,-4)`.
- Find the equation of the line of intersection of the planes `x + 2y + z + 4 = 0` and `2x - y - z - 4 = 0`. On one plot, plot the two planes, then superimpose the plot of the line of intersection. Note: There are a number of commands that you might find useful: hold, line, hidden. Help for each of these is available in Matlab's help files. For example, try either help line, or even better, doc line to open up Matlab's help desk. There are some real gems in this file. It will also take some experimentation to find a viewing window that nicely show both planes and the line of intersection.
