# Vectors and Matrices

In this section we are going to cover some linear algebra stuff. Octave is especially well designed for those purposes.

Vectors are the most basic objects in Octave. You already know how to define some: V=1:5 yields V=(1,2,3,4,5). You can also say:

But that’s a row vector. What if you want a column vector? There are two ways:

which means transpose (i.e.: convert rows into columns), or either you can do:

Either way it will work. You can cut vectors easily:

Matrices are not difficult to define either:

Of course, you can multiply a matrix with a column vector:

Solving a linear system is very easy. If your system is $A\vec x=\vec b$, with $A$ a matrix and $\vec b$ a vector, then you can formally write x = A \ b, and that will solve the system by gaussian reduction. An example, let’s solve the system:

So we write the matrix $A$ and the right hand side vector $\vec b$:

We can check easily that the solution is right:

as it should.

The special matrices are easy to find. For example, the identity, $I$, is called “eye” (yes, it’s someone’s idea of a joke):

Or the zero matrix:

## Exercises

• Solve the following linear system of equations:

Check the solution!

• Find the 10-th power of the following matrix