## Matrix and Vectors Construction

In this tutorial you will learn:

1.  Matrix and vector Construciton.
2. Zero Matrix
3. Ones Matrix
4. Identity Matrix
5. Linerally spaced vectors
6. Logarithmically spaced vectors

So lets get started!

# Matrices

Matrices in Matlab are one of the prime reasons for user to stick around.  It is called MATrixLABoratory for a reason. Otherwise, there are better alternatives when it comes to other features.

Now, a matrix has rows and columns. Kinda looks like this 😀

So, how do we make this sucker in Matlab?

Like this!

Or, you can go like this to save space:

m = [ 1, 1, 0;0, 1, 0;0, 0, 1];

A few more matrices are:

Column Vector:  m = [1;2;3;4]

Row vector: m = [1,2,3,4]

A 2×3 vector m = [1,2 ; 3,4 ; 5,6]

# Special Matrices

I am calling them special matrices because these matrices have a special property which can be exploited for our purpose:

### Zero Matrix

These matrices have nothing but zeroes in them. They are declared like:

zeros(20, 7)

### Ones Matrix

Contrary to Zero Matrix, Ones matrix have every element set as “1”. These matrices are declared like,

ones(4, 20)

### Identity Matrix

An identity matrix has ones in the diagonal while zeroes on every other element. It is made like this:

eye(10)

eye(4, 6)

### Linearly Spaced Vector

This command creates an evenly spaced vector between two numbers. The format is,

linspace(startingNumber, endingNumber, numberOfPoints)

e.g.

linspace(1, 10, 10)

### Logarithmically spaced vectors

This command creates Logarithmically spaced vector between two numbers. The format is,

logspace(RangeStartingfrom 10^THISNUMBER, RangingEndingAt 10^THISNUMBER, numberOfLogarithmicallyPoints)

So, logspace(1, 5, 10); will mean that we wish to create a logarithmically spaced vector of 10 points between 10^1 and 10^5

This just about covers the basics of Matrix and vectors. You have learnt the basics and construction of some of the most commonly used matrices in Matlab. Now, you have enough understanding to proceed towards matrix operations and manipulation.