0% found this document useful (0 votes)
5 views

Chap#2_Matrix_and_Linear_Algerbra_part1

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Chap#2_Matrix_and_Linear_Algerbra_part1

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

University of M’hamed BOUGARA of Boumerdes

Institute of Electrical and Electronics Engineering


(IGEE ex-INELEC)
Department of Power and Control engineering

EE421 – Computation and Simulation using


MATLAB /Simulink

Chapter 2: Matrix computations and linear algebra.


Part 1

Dr. A. AMMAR

01/20/2025 EE421 Dr. AMMAR 1


Chapter 2: Matrix computations and linear algebra.

1. Matrix generation
2. Matrix manipulation and operation
3. Solving linear equations
4. Polynomials Represented by Vectors

01/20/2025 EE421 Dr. AMMAR 2


Chapter 1: Matrix computations and linear algebra.

Matrices are the basic elements of the MATLAB environment. A matrix is a two-

dimensional array consisting of m rows and n columns. Special cases are

column vectors (n = 1) and row vectors (m = 1).


In this section we will illustrate how to apply different operations on matrices,

the inverse of a matrix, determinants, and matrix manipulation.


1 Matrix generation

Matrices are fundamental to MATLAB. Therefore, we need to become familiar


with matrix generation and manipulation. Matrices can be generated in several
ways.

01/20/2025 EE421 Dr. AMMAR 3


1.1. Entering a vector

A vector is a special case of a matrix. an array of dimension 1 × n is called a row


vector, whereas an array of dimension m × 1 is called a column vector

The elements of vectors in MATLAB are enclosed by square brackets and are
separated by spaces or by commas. For example, to enter a row vector, v, type

Column vectors are created in a similar way, however, semicolon (;) must separate
the components of a column vector,

01/20/2025 EE421 Dr. AMMAR 4


On the other hand, a row vector is converted to a column vector using the
transpose operator. The transpose operation is denoted by an apostrophe (’).

Thus, w(1) is the first element of vector w, w(2) its second element, and so forth.

Furthermore, to access blocks of elements, we use MATLAB’s colon operator (:).


For example, to access the first three elements of W, we write,

01/20/2025 EE421 Dr. AMMAR 5


Or, all elements from the third through the last elements,

1.2 Entering a matrix


A matrix is an array of numbers. To type a matrix into MATLAB you must:
• begin with a square bracket, [
• separate elements in a row with spaces or commas (,)
• use a semicolon (;) to separate rows
• end the matrix with another square bracket, ]

For example to enter a matrix A,

01/20/2025 EE421 Dr. AMMAR 6


Once we have entered the matrix, it is automatically stored and remembered in the
Workspace. We can refer to it simply as matrix A. We can then view a particular
element in a matrix by specifying its location. We write,

01/20/2025 EE421 Dr. AMMAR 7


1.3 Matrix generators

MATLAB provides functions that generates elementary matrices. The matrix of


zeros, the matrix of ones, and the identity matrix are returned by the functions
zeros, ones, and eye, respectively (Table.1).

Examples

01/20/2025 EE421 Dr. AMMAR 8


1.4 Special matrices

MATLAB provides a number of special matrices (see Table 2.5). These matrices
have interesting properties that make them useful for constructing examples and
for testing algorithms (Table.2).

01/20/2025 EE421 Dr. AMMAR 9


Examples

2. Matrix manipulation and operation


The MATLAB command for the determinant computation is det().

01/20/2025 EE421 Dr. AMMAR 10


The MATLAB command for the transpose operation is transpose(), ‘ .
For example:

The MATLAB command to compute the inverse of a matrix is inv(). For example,

01/20/2025 EE421 Dr. AMMAR 11


2.1 Matrix Operations

This section covers general mathematical operations and computations of


matrices, vectors, and eigenvectors. Table.3 lists the matrix operations their
command syntax.

01/20/2025 EE421 Dr. AMMAR 12


Examples

Note the difference between .^ and ^

01/20/2025 EE421 Dr. AMMAR 13


Example:
Performing Matrix Operations

Let’s perform some matrix operations—such as summation, subtraction,


multiplication, power, scalar multiplication, square root, mean, round, standard
deviations, and replicate/rotate/flip matrix—from the Command Window.

01/20/2025 EE421 Dr. AMMAR 14


01/20/2025 EE421 Dr. AMMAR 15
2.2 Other Matrices manipulations

We select elements in a matrix just as we did for vectors, but now we need two
indices. The element of row i and column j of the matrix A is denoted by A(i,j). Thus,
A(i,j) in MATLAB refers to the element Aij of matrix A. The first index is the row
number and the second index is the column number. For example, A(1,3) is an
element of first row and third column. Here, A(1,3)=3

Correcting any entry is easy through indexing.


Here we substitute A(3,3)=9 by A(3,3)=0.
The result is

01/20/2025 EE421 Dr. AMMAR 16


Creating a sub-matrix

To extract a submatrix B consisting of rows 2 and 3 and columns 1 and 2 of the matrix
A, do the following:

To interchange rows 1 and 2 of A, use the vector of row indices together with the
colon operator.

01/20/2025 EE421 Dr. AMMAR 17


To delete a row or column of a matrix, use the empty vector operator, [ ].

To determine the dimensions of a matrix or vector, use the command size. For
example

01/20/2025 EE421 Dr. AMMAR 18

You might also like