## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

### 3.8. Generation of Special Matrices

The following MATLAB commands/functions, which generate special matrices, are often used in engineering computations involving matrices:

1. zeros(p, q)

It returns a rectangular p × q matrix of all zeros.

Let p = 2 and q = 3, and execute the following commands.

```     p=2;
q=3;
A=zeros(p, q)
```

This will generate a (2 × 3) matrix with all elements equal to zero. The following result will be shown

```     A =
0    0    0
0    0    0
```
2. ones(p, q)

It returns a p × q matrix of all ones.

Let p = 2, q = 3, and execute the following commands.

```     p=2;
q=3;
A=ones(p, q)
```

It will generate a (2 × 3) matrix with all elements equal to one. The following result will be shown:

```     A =
1    1    1
1    1    1
```
3. eye(p, q)

It returns a p × q matrix with ones on the main diagonal and zeros ...

## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

No credit card required