Podcast
Questions and Answers
In MATLAB, what is an array?
In MATLAB, what is an array?
- A command used to clear the workspace
- A function used for plotting graphs
- A collection of data values organized into rows and columns (correct)
- A single numerical value
What is a one-dimensional array also known as?
What is a one-dimensional array also known as?
- Cell
- Scalar
- Matrix
- Vector (correct)
What is a two-dimensional array referred to as?
What is a two-dimensional array referred to as?
- Vector
- String
- Matrix (correct)
- Scalar
How are scalars treated in MATLAB?
How are scalars treated in MATLAB?
In MATLAB, how do you create a row vector?
In MATLAB, how do you create a row vector?
How can a vector element be accessed in MATLAB?
How can a vector element be accessed in MATLAB?
In MATLAB, at what index does the vector start?
In MATLAB, at what index does the vector start?
What does the command length(x)
return in MATLAB?
What does the command length(x)
return in MATLAB?
What does the command y = x'
do in MATLAB?
What does the command y = x'
do in MATLAB?
What does the command dot(x, y)
calculate in MATLAB?
What does the command dot(x, y)
calculate in MATLAB?
What does the command cross(x, y)
return in MATLAB?
What does the command cross(x, y)
return in MATLAB?
What does the function randi()
do in MATLAB?
What does the function randi()
do in MATLAB?
In matrix creation, what are used to separate elements in a row?
In matrix creation, what are used to separate elements in a row?
In matrix creation, what are used to separate rows?
In matrix creation, what are used to separate rows?
What MATLAB command is used to generate a matrix of all zeros?
What MATLAB command is used to generate a matrix of all zeros?
What does the command eye(n)
do in MATLAB?
What does the command eye(n)
do in MATLAB?
In MATLAB, what does the operator .*
do?
In MATLAB, what does the operator .*
do?
In MATLAB, what is the function of the operator ./
?
In MATLAB, what is the function of the operator ./
?
What is the equivalent of $B = A^T$ in MATLAB?
What is the equivalent of $B = A^T$ in MATLAB?
How can you calculate the inverse of matrix A in MATLAB?
How can you calculate the inverse of matrix A in MATLAB?
In MATLAB, what does the function eig(x)
calculate?
In MATLAB, what does the function eig(x)
calculate?
Flashcards
What is an array?
What is an array?
A collection of data values organized into rows and columns, known by a single name.
What is a vector?
What is a vector?
A one-dimensional array of numbers.
What is a matrix?
What is a matrix?
A two-dimensional array of numbers.
Scalars in MATLAB
Scalars in MATLAB
Signup and view all the flashcards
Vector Definition
Vector Definition
Signup and view all the flashcards
Row Vector Separator
Row Vector Separator
Signup and view all the flashcards
Column Vector Separator
Column Vector Separator
Signup and view all the flashcards
Vector addressing
Vector addressing
Signup and view all the flashcards
Colon Notation
Colon Notation
Signup and view all the flashcards
x = start:end (MATLAB)
x = start:end (MATLAB)
Signup and view all the flashcards
length(x) (MATLAB)
length(x) (MATLAB)
Signup and view all the flashcards
y = x' (MATLAB)
y = x' (MATLAB)
Signup and view all the flashcards
dot(x, y) (MATLAB)
dot(x, y) (MATLAB)
Signup and view all the flashcards
sum(x) (MATLAB)
sum(x) (MATLAB)
Signup and view all the flashcards
cross(x, y) (MATLAB)
cross(x, y) (MATLAB)
Signup and view all the flashcards
randi() (MATLAB)
randi() (MATLAB)
Signup and view all the flashcards
rand() (MATLAB)
rand() (MATLAB)
Signup and view all the flashcards
What is a Matrix?
What is a Matrix?
Signup and view all the flashcards
Matrix Addressing in MATLAB
Matrix Addressing in MATLAB
Signup and view all the flashcards
zeros(M, N) (MATLAB)
zeros(M, N) (MATLAB)
Signup and view all the flashcards
ones(M, N) (MATLAB)
ones(M, N) (MATLAB)
Signup and view all the flashcards
eig(x) (MATLAB)
eig(x) (MATLAB)
Signup and view all the flashcards
eye(n) function
eye(n) function
Signup and view all the flashcards
.* operator
.* operator
Signup and view all the flashcards
.^ operator
.^ operator
Signup and view all the flashcards
Study Notes
- EE 153: Introduction to MATLAB, Module 2 covers vectors, matrices, and array operations.
Learning Objectives
- Understand the basics of vectors and matrices.
- Learn matrix operations and array manipulation.
- Apply element-wise operations and matrix algebra in MATLAB.
- Use matrix operations for solving linear equations.
- Practice solving linear equations in power systems using matrix operations.
Array
- An array is a collection of data values organized into rows and columns, known by a single name.
- Arrays can be classified as vectors and matrices.
- A vector is a one-dimensional array.
- A matrix is a two-dimensional array.
- Scalars are treated as arrays by MATLAB (1 row and 1 column).
- Scalars are quantities represented just by their numerical value, such as 3, -5, 0.368.
Vectors
- A vector is an array of numbers or a list of scalar values in a one-dimensional array of numbers, which can be in a row or column.
- A = [5 6 7 8 9] is a 1 x 5 array with 5 elements, representing a row vector.
- Comma "," is used to separate each number for a row vector.
>> VR = [6, 7, 8]
results in VR =6 7 8
- Semicolon ";" is used to separate each number for a column vector.
>> VC = [5; 6; 7]
results in VC as a column vector with elements 5, 6, and 7.
Vector Addressing
- Vector Addressing involves accessing a vector element in MATLAB with an integer index enclosed in parentheses.
- For example, from vector A,
>> A(3)
results inans = 7
, which is the 3rd element of vector A. - Colon notation may be used to address a block of elements, with the syntax
(start:increment:end)
. - "start" is the starting index, "increment" is the amount to add to each successive index, and "end" is the ending index.
(start: end)
is used if the increment is 1.- E.g.,
>> A(1:3)
results inans = 5 6 7
, which are the 1st to 3rd elements of vector A. - MATLAB index starts at 1.
Some Useful Commands
x = start: end
creates a row vector x starting with "start," counting by one, and ending at "end."length(x)
returns the length of vector x.y = x'
transposes vector x.dot(x, y)
returns the scalar dot product of the vectors x and y.sum(x)
returns the sum of all numbers in x.cross(x, y)
returns the vector as the cross product of x and y.randi()
uniformly distributes random integers.rand()
generates a uniformly distributed array of random numbers between 0 and 1.
Matrices
- A matrix is a two-dimensional array.
- A matrix having i rows and j columns is called an i x j matrix.
- Matrix creation begins with "[" and ends with "]".
- Spaces or commas are used to separate elements in a row.
- A semicolon or enter is used to separate rows.
- Elements are arranged in rows (i) and columns (j).
>> f = [ 1 2 3; 4 5 6]
creates a matrix f.>> M = [4, 8, 9, 6; 9, 6, 9, 6; 3, 6, 9, 6]
creates a matrix M.
Matrix Addressing
- The function
matrixname(row, column)
is used for matrix addressing. - For example,
>> f(2,3)
returns the element in the 2nd row and 3rd column of matrix f. >> h(:,1)
selects all rows in the first column of matrix h.- A colon may be used in place of a row or column reference to select the entire row or column.
>> a = [1, 2, 3; 4, 5, 6]
defines matrix a in MATLAB.>> a(1,:)
selects row 1 and every column in matrix a.>> a(1, 1:2)
selects the first two elements in the first row in matrix a.>> a(:)
changes matrix a into a column vector.
Special Matrices/Useful Commands
zeros(M,N)
creates an MxN matrix of zeros.- Example:
x = zeros(1,3)
results in x =0 0 0
- Example:
ones(M,N)
creates an MxN matrix of ones.- Example:
x = ones(1,3)
results in x =1 1 1
- Example:
eig(x)
finds the eigenvalues of x.- Example:
x = [1,4;3,2]
,lambda = eig(x)
, results inlambda = -2 5
- Example:
Matrix Operations
- Transpose:
B = A'
- Identity Matrix:
eye(n)
returns an n x n identity matrix.eye(m,n)
returns an m x n matrix with ones on the main diagonal and zeros elsewhere.
- Addition and subtraction:
C = A + B
,C = A - B
- Scalar Multiplication:
B = αA
, where α is a scalar - Matrix Multiplication:
C = A*B
- Matrix Inverse:
B = inv(A)
. A must be a square matrix;rank(A)
returns the rank of the matrix A. - Matrix Powers:
B = A.^2
squares each element in the matrix.C = A*A
computes A*A, and A must be a square matrix.
- Determinant:
det(A)
, A must be a square matrix. - A, B, C are defined as matrices, and m, n, α are scalars.
Operators (Element-wise)
.*
is the element-by-element multiplication operator../
is the element-by-element division operator..^
is the element-by-element power operator.- Example of element-by-element division:
- If
>> a = [1, 2, 12]
and>> b = [1, 1, 2]
- Then
>> a ./ b
results in:ans = 1 2 6
- If
- Example of element-by-element multiplication:
- If
>> a = [1, 2, 3]
and>> b = [0, 1, 2]
- Then
>> a .* b
results in:ans = 0 2 6
- If
- Example of element-by-element power:
- If
>> a = [1, 2, 3]
and>> b = [0, 1, 2]
- Then
>> a .^ b
results in:ans = 1 2 9
- If
Practice 1
- Consider the vector: A = [4, 8, 15, 16, 23, 42]
- Write MATLAB commands to extract the first three elements of A using colon notation.
- Write commands to replace the fourth element of A with 100.
- Write commands to create a new vector B consisting of the last three elements of A.
Practice 2
- Create a 3×3 matrix M in MATLAB with rows: [1 2 3], [4 5 6], and [7 8 9].
- Extract the entire second row using proper matrix addressing.
- Compute a new matrix where each element of M is squared using the element-by-element power operator.
- Replace the third column of M with the vector [10; 11; 12].
Practice 3
- Solving Systems of linear equations, like the one below:
- 3a + 2b - c = 10
- -a + 3b + 2c = 5
- a - b - c = -1
- Formulate the coefficient matrix and constant vector corresponding to the system.
- Solve the system using the matrix inverse approach.
- Solve the same system using MATLAB's matrix division operator.
- Verify that both methods yield the same solution.
Practice 4
- Modeling of the Kirchhoff's Voltage Law (KVL) states that the sum of all voltages around a closed loop in a circuit must be equal to zero.
- Write a set of linear equations for a circuit with m loops.
- Use symbolic math tool box
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.