MLB4 112327
MLB4 112327
In MATLAB, matrices and vectors are fundamental data structures. MATLAB (Matrix
Laboratory) is designed for matrix-based computations, making it essential to understand how
to create, manipulate, and operate on them.
4.1 Basics of Matrices and vectors
4.1.1 Creating Vectors
A vector is a one-dimensional array of numbers. It can be a row vector or a column vector.
Row Vector
A = [1, 2, 3, 4]; % Using square brackets with commas or spaces
B = [5 6 7 8]; % Spaces also work
Column Vector
C = [1; 2; 3; 4]; % Using semicolons to separate rows
Generating Vectors Automatically
x = 1:5; % Creates a row vector [1 2 3 4 5]
y = 1:2:10; % [Start:Step:End] -> [1 3 5 7 9]
z = linspace(0, 10, 5); % Generates 5 equally spaced points from 0 to 10
Summary Table
Concept Example
Create Vector v = [1 2 3]
Create Matrix M = [1 2; 3 4]
Access Elements M(2,1)
Matrix Addition A+B
Matrix Multiplication A*B
Element-wise Multiplication A .* B
Transpose A'
Inverse inv(A)
Solve Linear System A\b
Eigenvalues & Vectors [V,D] = eig(A)