```
```{raw} latex
%%start demo%%
```
Here we create an adjacency matrix for a graph on four nodes.
```{code-cell}
A = [ 0 1 0 0; 1 0 0 0; 1 1 0 1; 0 1 1 0 ]
```
```{index} ! Julia; graphplot
```
The `graphplot` function makes a visual representation of this graph.
```{code-cell}
graphplot(A,names=1:4,markersize=0.2,arrow=6)
```
Since this adjacency matrix is not symmetric, the edges are all directed, as indicated by the arrows. Here are the counts of all walks of length 3 in the graph:
```{code-cell}
A^3
```
If the adjacency matrix is symmetric, the result is an undirected graph: all edges connect in both directions.
```{code-cell}
A = [0 1 1 0;1 0 0 1;1 0 0 0;0 1 0 0]
graphplot(A,names=1:4,markersize=0.2)
```
```{raw} html

```
```{raw} latex
%%end demo%%
```
The representation of a graph by its adjacency matrix opens up the possibility of many kinds of analysis of the graph. One might ask whether the nodes admit a natural partition into clusters, for example. Or one might ask to rank the nodes in order of importance to the network as determined by some objective criteria—an application made famous by Google's PageRank algorithm, and one which is mathematically stated as an {ref}`eigenvalue
```
```{raw} latex
%%start demo%%
```
```{index} ! Julia; Images
```
The `Images` package has many functions for image manipulation, and `TestImages` has some standard images to play with.
```{code-cell}
img = testimage("mandrill")
```
The variable `img` is a matrix.
```{code-cell}
size(img)
```
However, its entries are colors, not numbers.
```{code-cell}
img[100,10]
```
```{index} ! Julia; eltype
```
You can use `eltype` to find out the type of the elements of any array.
```{code-cell}
eltype(img)
```
It's possible to extract matrices of red, green, and blue intensities, scaled from 0 to 1.
```{code-cell}
R,G,B = red.(img),green.(img),blue.(img);
@show minB,maxB = extrema(B);
```
Or we can convert the pixels to gray, each pixel again scaled from 0 to 1.
```{code-cell}
Gray.(img)
```
In order to do our usual operations, we need to tell Julia that we want to interpret the elements of the image matrix as floating-point values.
```{code-cell}
A = Float64.(Gray.(img))
A[1:4,1:5]
```
We can use `Gray` to reinterpret a matrix of floating-point values as grayscale pixels.
```{code-cell}
Gray.(reverse(A,dims=1))
```
```{raw} html

```
```{raw} latex
%%end demo%%
```
Representation of an image as a matrix allows us to describe some common image operations in terms of linear algebra. For example, in {numref}`section-matrixanaly-svd` we will use the singular value decomposition to compress the information, and in {numref}`section-krylov-matrixfree` we will see how to apply and remove blurring effects.
## Exercises
1. ✍ Consider the terms *numerical*, *analysis*, and *fun*. Write out the term-document matrix for the following statements:
**(a)** Numerical analysis is the most fun type of analysis.
**(b)** It's fun to produce numerical values for the digits of pi.
**(c)** Complex analysis is a beautiful branch of mathematics.
2. ✍ Write out the adjacency matrix for the following graph on six nodes.
```{image} littlegraph.png
:alt: little graph
:width: 500px
:align: center
```
3. ✍ Here is a graph adjacency matrix.
:::{math}
\begin{bmatrix}
0 & 1 & 0 & 1 & 0 & 1 & 0 \\
1 & 0 & 1 & 0 & 0 & 1 & 0 \\
0 & 1 & 0 & 0 & 1 & 0 & 1 \\
1 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 1 & 0 \\
1 & 1 & 0 & 0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & 0
\end{bmatrix}
:::
**(a)** How many vertices are adjacent to vertex 5?
**(b)** How many edges are in the graph?
**(c)** Is the graph directed or undirected?
**(d)** Draw the graph.
4. ⌨ Refer to {numref}`Demo %s