MATLAB Programming/Vector and Matrices

What is scalar,vector and matrix ?

edit
 

Scalar

edit

Scalars are the physical quantities that are described by magnitude only. In other words, scalars are those quantities that are represented just by their numerical value, such as 3, -5, 0.368, etc.

Vector

edit

A vector is an array of numbers or a list of scalar values in one dimensional array of numbers (can be in a row or column).


This example vector A below is row vector

 

This example vector B below is column vector

 

Matrix

edit
 
Geographical matrix - systematic and regional geography

A matrix is an ordered rectangular array arrangement of numbers. They are stored as two-dimensional arrays in MATLAB.
A matrix having m rows and n columns is called a matrix of order m × n or simply m × n matrix.
It can be represented by one or more rows (i) AND one or more columns (j).

Back in Introduction chapter , MATLAB was originally designed to carry out operations with matrices, and received the name of MATrix LABoratory that subsequently was reduced to MATLAB.

It is possible to find applications of matrices not only in the mathematics areas, but also in a great deal of applications in engineering, in physics, in finance, in accounting, in chemistry and in biology, perhaps more.


There are many types of matrices with followings as shown

Rectangular Matrix (Where no. of row and column are unequal) Square Matrix (Where no. of row and column are same) Row Matrix (Matrix with one row , aka row vector) Column Matrix (Matrix with one column , aka column vector) Diagonal Matrix (Square Matrix with non-diagonal elements equal to zero )
 

 

 

 

 


Scalar in MATLAB

edit

Scalar in MATLAB looks like assigning a variable to a number such as followed:

 a = 6

Vectors in MATLAB

edit

You can type following in MATLAB

For row vector , just type comma "," to separate each number

  >> VR = [6,2,5]
  VR =
     6     2     5

For column vector , just type semicolon ";" to separate each number

  >> VC = [9;1;6]
  VC =
     9
     1
     6

Matrix in MATLAB

edit

In MATLAB, to create matrix (or matrices), there is 3 important operator to be used

(a) Bracket "[" "]" as container for the matrix
(b) Comma , as matrix row separator
(c) Semicolon ; as matrix column separator

For example, we are creating 4X3 matrix in MATLAB using following commands.

>> M = [4,8,9,6;9,6,9,6;3,6,9,6]

M =
     4     8     9     6
     9     6     9     6
     3     6     9     6