Thursday, May 16, 2024

concatenating, Determinant of a matrix, String:

Must read

Concatenating Matrices:

If you concatenate two matrices it creates a large matrix. Pair of square braces [] is a concatenate operator.

Matlab as two types of concatenate as follows:

Horizontal concatenation:

When you concatenate two matrix which are separated by using commas, they are called horizontal concatenation.

Vertical concatenation:

When you concatenate two matrix which are separated by using semicolon, they are called vertical concatenation.

Let us consider an example of this two concatenation:

a = [10 12 15; 14 8 6; 17 8 9]

b = [12 11 45; 8 1 -9; 18 2 11]

 c = [a, b]

d = [a; b]

Output will be obtained as

a= 10 12 15

     14 8 16

     17 8 9

b = 12 31 45

      8 0 -9

      45 2 11

 c = 10 12 15 12 11 45

       14 8   16   8   1 -9

       17 8   9   18 2 11

d=10 12 23

     14 8 6

     27 8 9

   12 31 45

   8 0 -9

   45 2 11

Matrix multiplication:

Where in matrix multiplication, the elements of rows in the first matrix is multiplied with the columns in the second matrix.

In matlab matrix multiplication is represented by ‘*’.

In matrix multiplication column in A matrix is equal to rows in B matrix.

Let us consider an example

a = [2 3 4; 1 2 3; 1 3 5]

b = [2 3 -1; 2 1 3; 5 0 -2;]

prod = a * b

Output will be

prod = 30 9 -1

           21 5 -1

           33 6 -2

Determinant of matrix:

Determinant of matrix is determined by using det function in matlab, and it represented of a matrix A is det(A). Let us consider an example.

a = [ 1 2 6; 2 3 4; 1 4 5]

 det(a)

output will be

ans =17

Inverse of Matrix:

The inverse of a matrix in matlab of A is represented by A−1 such which holds the following relationship:

AA−1 = A−1 A = 1

If the determinant of matrix is zero then the inverse will not exist and the matrix is singular.

Inverse of matrix is determined by inv function in matlab and it represented by inv(A)

STRING:

The string is really a vector whose additives are the numeric codes for the characters. Matlab has exclusive kind of textual content string.

Character array: best when considering individual letters of text, text is stored in two-dimensional array. The rule of all rows should have same number of column.

Cell array: best when considering word.

Let us create an uncomplicated string that may include a unique quote.

msg = ‘You”re right!’

            msg =

You’re right!

create the string, name, the usage of strategies of concatenation.

name = [‘Thomas’ ‘ R. ‘ ‘Lee’]

name = strcat(‘Thomas’,’ R.’,’ Lee’)

Create a vertical array of strings.

C = strvcat (‘Hello’,’Yes’,’No’,’Goodbye’)

C =

Hello 

Yes   

No    

Goodbye

Create a cell array of strings.

S = {‘Hello’ ‘Yes’ ‘No’ ‘Goodbye’}

S =

    ‘Hello’    ‘Yes’    ‘No’    ‘Goodbye’

- Advertisement -

More articles

- Advertisement -

Latest article