Getting Started

Complex number

A complex number has a real part and an imaginary part, and the imaginary unit is the square root of -1.

sqrt(-1)

ans = 0.0000 + 1.0000i

To represent the imaginary part of a complex number, use i or j.

c = [3+4i, 4+3j; -i, 10j]

c = 2×2 complex
   3.0000 + 4.0000i   4.0000 + 3.0000i
   0.0000 - 1.0000i   0.0000 +10.0000i

Matrices and arrays

To create an array with four elements per row, separate elements with commas (,) or spaces

a = [1 2 3 4]

MATLAB will execute the above statement and return the following results:

a = 1×4
     1     2     3     4

#Create a matrix with multiple rows

a = [1 3 5; 2 4 6; 7 8 10]

a = 3×3
     1     3     5
     2     4     6
     7     8    10

#5×1 column vector of zeros

z = zeros(5,1)

z = 5×1
     0
     0
     0
     0
     0

concatenation

Concatenation is the process of joining arrays to form larger arrays. In fact, the first array is formed by concatenating its elements. Pairs of square brackets [] are concatenation operators.

A = [a,a]

A = 3×6
     1     3     5     1     3     5
     2     4     6     2     4     6
     7     8    10     7     8    10

Concatenating arrays next to each other using commas is called horizontal concatenation. Each array must have the same number of rows. Likewise, semicolons can be used for vertical concatenation if the arrays have the same number of columns.

A = [a; a]

A = 6×3
     1     3     5
     2     4     6
     7     8    10
     1     3     5
     2     4     6
     7     8    10

Matrix and array operations

MATLAB allows you to use a single arithmetic operator or function to manipulate all values ​​in a matrix

a + 10

MATLAB will execute the above statement and return the following results:

ans = 3×3
    11    13    15
    12    14    16
    17    18    20

sin(a)

MATLAB will execute the above statement and return the following results:

ans = 3×3
    0.8415    0.1411   -0.9589
    0.9093   -0.7568   -0.2794
    0.6570    0.9894   -0.5440

To transpose a matrix, use single quotes (')

a'

ans = 3×3
     1     2     7
     3     4     8
     5     6    10

Perform standard matrix multiplication using the * operator, which computes the inner product between rows and columns

p = a*inv(a)

p = 3×3
    1.0000         0         0
         0    1.0000         0
         0         0    1.0000

Introduction

MATLAB is short for matrix laboratory

Comments