Matlab Matrix

Matlab Matrix

What is a Matrix?

a rectangular array of expressions arranged in particular rows and columns that is treated as a solitary substance and controlled by specific standards.

MatlabMatrix

A Framework called matrix, is a 2D exhibit of components or elements. The matrix is made by appointing the array components that are delimited by spaces or commas and utilizing semicolons to check the finish of each column. To comprehend it better, presently we have to look at certain guides.

Let us take matrices A1 and B1. In this case A1 is a m x n matrix and B1 is a n x p matrix, they could be duplicated together to create a m x n matrix C. Matrix concatenation is conceivable just if the quantity of sections n in A is equivalent to the quantity of lines n in B.

Working with matrix

Creating a matrix

The below script file shows us how to create a matrix j and i, using square braces and semi colons.

 % to create a matrix
 %j represents a Number Matrix
 j = [0 8 3;4 5 6;7 3 9]
 %String Matrix
 i = ['play;'home'] 

Output: we have created two matrices, one is 3x3 number matrix and another is a 2x4 string matrix.

Knowing the matrix size

To get the size of the matrix we simply use size() function, and pass the matrix as argument to the size() function.

The below script file shows us how to know the size of the matrix x1 and y1, using size function.

 % to know the size of a matrix
 % Creating matrices x1
 x1 = [91 2 13 4;41 5 6 71;79 8 9 10];
 xSize = size(x1)
 y1=['play';'home'];
 ySize = size(y1) 

Output:

If we run the above script file we obtain size of the matrix, this function returns no of rows and columns. In our example, size of x1 is 3x4 and size of y1 is 2x4 is returned.

Referencing the matrix

 To reference matrix elements, we write matrix(m, n). Here rows and columns indexes are represented by m and n. 

Let us drivedeep to know how it works through examples running on command line of Matlab environment.

 % to access
 % a particular element
 % Creating matrices x
 i = [11 21 31 4;4 51 6 71;7 8 9 10];
 i(3,2)
 y=['play';'home'];
 y(1,2) 

Output:

We tried to access (3,2) element of matrix i, and (1,2) element of matrix y, we successfully executed the code.

Delete column or row

Suppose we want to remove a particular column or row from our matrix; we can modify it according to our requirements. As we see in the mentioned example, we first created a matrix X1, and then we tried to delete 3rd row of the matrix.

The below script file shows us how to delete a row from a matrix X1.

 % to delete
 % a row or a column
 % Creating matrices
 X1 = [18 22 31 42;42 52 63 37;17 18 9 10];
 % Deleting 3rd row of
 % a matrix
 X1(3,:) = []
 % Deleting 3rd column in
 % every row of a matrix
 X1(:,3) = [] 

Output: As we can use our code can reflected in our output, 3rd row has been deleted from the matrix X1.

Operations on matrix

Matlab gives inbuilt usefulness to making the matrix out the qualities to it. There are a few numerical and geometrical calculations upheld by Matlab programming language. A portion of the number juggling procedure on the matrix in Matlab are multiplication, addition, subtraction, transpose, complex, power.

Operation nameDescription  
Cross()To perform cross product of matrices
Dot()To perform dot product of matrices
TransposeTo perform transpose of matrices
ComplexTo perform complex operation of matrix
PowerTo perform power operation of matrices

1.Cross product

o = cross(A1,B1) 

If A1 and B1 are vectors, they are of same size.

If A1 and B1 matrices of same size are created. The cross() function treats A1 and B1 as three-element vectors. The cross product of two matrices A1 and B1 is calculated by cross() function of corresponding vectors.

Example:

 A1 = randi(11,4,3)
 
A1 =

     2    11    11
     5     8     8
    11     1     9
     9    10     9
 B1 = randi(24,4,3)
 
B1 =

    10     1    20
    16     7    17
     5     2     8
    17     3    23
 %The cross product of A and B is calculated here.
 o = cross(A1,B1)
 
o =

   209    70  -108
    80    43   -93
   -10   -43    17
   203   -54  -143 

2. Dot product

o = dot(A1,B1)

If A1 and B1 are vectors, having the same length.

If A1 and B1 are multidimensional arrays or matrices, of same size. The dot function treats A1 and B1 as vectors and then calculates the dot product, by maintaining the size of first array dimension not equal 1.Let us explore it further through examples running on command line of Matlab environment.

Example:

Let us create two multidimensional arrays A1 and B1 and perform the desired operation to obtain the required output.

 A1 = cat(3,[1 1;1 1],[2 3;4 5],[6 7;8 9])
 A1 =
 A1(:,:,1) =
      1     1
      1     1
 A1(:,:,2) =
      2     3
      4     5
 A1(:,:,3) =
      6     7
      8     9
 B1 = cat(3,[2 2;2 2],[10 11;12 13],[14 15; 16 17])
 B1 =
 B1(:,:,1) =
      2     2
      2     2
 B1(:,:,2) =
     10    11
     12    13
 B1(:,:,3) =
     14    15
     16    17 

3.Transpose

B1 = A1.'

This returns the transpose (nonconjugate)of A1. Transpose means interchanging the row and column index for each corresponding element. In case of complex elements, then A1.', sign of the imaginary parts is not effected. For instance, if have taken  A1(3,2) is 1+2i and B1 = A1.', then B1(2,3) is also 1+2i.

Let us execute on command line of Matlab environment and check out.

Example:

 A1 = magic(4)
 
A1 =

    16     2     3    13
     5    11    10     8
     9     7     6    12
     4    14    15     1
 B1 = A1.'
 
B1 =

    16     5     9     4
     2    11     7    14
     3    10     6    15
    13     8    12     1 

4.comple matrix

Example

 A = [1 3 4-1i 2+2i; 0+1i 1-1i 5 6-1i]
 A = 2×4 complex
  
    1.0000 + 0.0000i   3.0000 + 0.0000i   4.0000 - 1.0000i   2.0000 + 2.0000i
    0.0000 + 1.0000i   1.0000 - 1.0000i   5.0000 + 0.0000i   6.0000 - 1.0000i
  
 B = A.'
 B = 4×2 complex
  
    1.0000 + 0.0000i   0.0000 + 1.0000i
    3.0000 + 0.0000i   1.0000 - 1.0000i
    4.0000 - 1.0000i   5.0000 + 0.0000i
    2.0000 + 2.0000i   6.0000 - 1.0000i 

5.Matrix multiplication

Example:

 A = [1 3 5; 2 4 7];
 B = [-5 8 11; 3 9 21; 4 0 8];
 Calculate the product of A and B.
 C = A*B
 C = 2×3
  
     24    35   114
     30    52   162 

6.Power

To find power of elements of a matrix, we can simply use “^” symbol or sometimes we use the function mpower() to find the power of a matrix.

Example:

 q = [1 2; 3 4];
 z = q^2
  
 z = 2×2
  
      7    10
     15    22 

7.Square root

Matrix representation is created of the fourth difference operator, A1. Symmetric and positive definite are two attributes mandatory for the matrix created.

Let us explore it further through examples running on command line of Matlab environment.

 A1 = [51 -4 11 10 0; -14 16 -4 11 0; 11 -4 6 -4 21; 20 21 -24 6 -24; 20 0 21 -4 26]
 
A1 =

    51    -4    11    10     0
   -14    16    -4    11     0
    11    -4     6    -4    21
    20    21   -24     6   -24
    20     0    21    -4    26 

Calculate the unique positive definite square root of A using sqrtmX is the matrix representation of the second difference operator.

 X1 = round(sqrtm(A1))
 
X1 =

   7.0000 + 0.0000i   0.0000 + 0.0000i   1.0000 - 1.0000i   1.0000 + 0.0000i   0.0000 + 0.0000i
  -1.0000 + 1.0000i   4.0000 + 1.0000i  -1.0000 + 0.0000i   1.0000 - 1.0000i   1.0000 - 1.0000i
   1.0000 + 0.0000i   0.0000 + 0.0000i   2.0000 + 2.0000i  -1.0000 + 0.0000i   3.0000 - 1.0000i
   3.0000 - 2.0000i   3.0000 - 2.0000i  -2.0000 + 2.0000i   2.0000 + 2.0000i  -3.0000 + 1.0000i
   2.0000 + 0.0000i   0.0000 + 0.0000i   3.0000 - 1.0000i   0.0000 + 0.0000i   4.0000 + 1.0000i 

7.Page transpose

Example

Create a 3-D array Z, and pagetranspose() is used to transpose array’s each page.

Let us explore it further through examples running on command line of Matlab environment.

 o = repelem(1:3,3,1);
 Z = cat(3,o,2*o,3*o)
 Z =
 Z(:,:,1) =
      1     2     3
      1     2     3
      1     2     3
 Z(:,:,2) =
      2     4     6
      2     4     6
      2     4     6
 Z(:,:,3) =
      3     6     9
      3     6     9
      3     6     9
 Y = pagetranspose(A)
 Y=
 Y(:,:,1) =
      1     1     1
      2     2     2
      3     3     3
 Y(:,:,2) =
      2     2     2
      4     4     4
      6     6     6
 Y(:,:,3) =
      3     3     3
      6     6     6
      9     9     9 

Related Topics

Matlab Calculus

Analytics Calculus is significant in various fields like designing, physical science, and different sciences, yet the estimations are finished by machines or PCs, regardless of whether they are into Physics...

3 minutes read.

MATLAB Variables

What are variables? A variable is a storage location or a container to store or hold data. In programming, variables are used to reservedata created by the programmers so that it...

4 minutes read.

MATLAB Vector

Introduction to MATLAB vector Vectors are one of the representations of arrays. It tends to be addressed in two different ways line(row) vector and section(column) vector. A vector is defined as...

5 minutes read.

Matlab DFT and IDFT

Matlab Program- (DFT and IDFT of a sequence) Program for DFT (Discrete Fourier change) and IDFT (Inverse discrete Fourier change) of a sequence. Program explanation: In Arithmetic, the discrete Fourier change (DFT) changes...

3 minutes read.

MATLAB Loops

Loops in programming Concept of looping is used to execute instructions repeatedly. It helps coders to reduce lines of code by setting a condition. In looping first a condition is fixed,...

3 minutes read.

MATLAB Program - To Solve Differential Equation Using Euler’s Method

Using Euler's method to solve differential equation Can you imagine a point where we do not use differential equation to solve differential condition? Truth be told, there are a few different...

3 minutes read.

MATLAB vs Other Languages

MATLAB vs Other Languages If we try to find which is the best computer programming languages, the answer is not straightforward, and that might sound similar to asking which is the...

3 minutes read.

Matlab function

Introduction: Functions in MATLAB are composed with code that link one variable with another, and yielded output is connected precisely to one specific information that shapes a significant piece of any...

6 minutes read.

MATLAB Butterworth filter

What is Butterworth filter? The Butterworth channel is a kind of sign preparing channel intended to have a recurrence reaction as level as conceivable in the passband. It is likewise alluded...

3 minutes read.

MATLAB Setup And Environment

MATLAB Setup And Environment MATLAB System Requirements As we have already discussed the prerequisite to begin the learning journey of MATLAB now let us drive into some technical system requirements. RAMàMinimum 4GB or...

3 minutes read.

matlab Integral

What is integration? In maths, Integral allots numbers to functions in a manner that portrays relocation, region, volume, and different ideas that emerge by consolidating tiny information. The way toward discovering...

5 minutes read.

matlab polynomials

In mathematics, a polynomial is an articulation comprising of indeterminates factors and the respective coefficients, that includes just the tasks of augmentation, expansion, deduction, and non-negative whole number exponentiation of...

4 minutes read.

MATLAB’s Array

What is an Array? An array is a collection of similar datatype elements in contiguous memory location. Every element in array is stored with an index number starting from 0. First...

4 minutes read.

Matlab Matrix

Matlab Matrix What is a Matrix? a rectangular array of expressions arranged in particular rows and columns that is treated as a solitary substance and controlled by specific standards. MatlabMatrix A Framework called matrix,...

5 minutes read.

MATLAB Simulink examples

We will discuss few examples to understand different use-cases of MATLAB’s Simulink. Simulink is basically MATLAB-based. Its essential interface is a graphical square charting apparatus and an adaptable arrangement of square...

4 minutes read.

Matlab Graphic image

Matlab’s Graphic image Images are stored as arrays of numeric data in MATLAB® environment, so you can perform various sort of analysis on them to better visualize it. Picture Processing applications are given...

3 minutes read.

MATLAB Tutorial

Introduction of MATLAB In this MATLAB(stands for matrix laboratory) tutorial, we will cover core concepts of MATLAB and provide a solid foundation to enhance high computing skills. We are going to...

4 minutes read.

Matlab Algebra

Up until now, we have seen that every one of the models work in MATLAB just as its GNU, then again called Octave. In any case, for addressing fundamental mathematical...

6 minutes read.

MATLAB Gaussian Pulse

Gaussian pulse shape description: The diagram of a Gaussian is a trademark symmetric "ringer bend" shape. The boundary an is the stature of the bend's pinnacle, b is the situation of...

3 minutes read.

Matlab Unit impulse signal generation

What is the Necessity of learning Matlab programs? Matlab Programming Examples give you an idea of typical Matlab programs in a nutshell.Matlab programming should be utilizing object-oriented programming, GUI programming, and...

3 minutes read.