Free Online Course in Programming - Matlab and Octave
Taking this course, one can easy learn how to use Octave and Matlab software and write your own programs.
This programming languages are object-oriented and based on elementary algebra (vector and matrix objects). Thus, during that course one can learn also elementary math, mostly algebra.
Matlab and Octave Course - Content
- Elementary Commands
- Work With M-File
- Vectors and Matrices
- Logical Operators
- Conditional Instructions
- Matrix Equations
- Gauss Elimination Method
- Cholesky Factorization
- Least Squares Problem
- 2D Graphical Data Representation
- Complex Numbers
- Script Functions
- Anonymous Functions
- Inline Functions
- Other MATLAB/Octave Data Types
- Multi – Dimensional Arrays
- Dialog Windows (MATLAB)
- UI Objects (MATLAB)
- 3D Graphical Data Representation
- Graphics 3D
- Trimesh and Delaunay Triangulation
- Sound Effects
- Some Mathematical Problems
- The Newton Algorithm
- Discrete Mapping
- Numerical Differentiation
- Numerical Integration
To get access to this free online course create your account on the taketechease:
If you already have one just Log In.
One can find below a piece of this course.
Vectors and Matrices
Run Octave or MATLAB.
Vector is a mathematical object usually used to describe a point position.
In n – dimensional space it has the structure: a = [a1, a2, a3, …, an] where ai denotes the i-th coordinate of a being the vector projection on the i-th direction. As programmers we do not care of its pure mathematical meaning. For us it is a set of numbers written either in a single row or in a single column. The calculus (rules how to operate on vectors) is also defined. Using vectors make our programs much simpler.
In MATLAB/Octave to make a vector : operator is used. Let's create a vector
- a = i:n gives the row vector a = [i, i+1, ..., n] with the step k = 1
- when i>n we get the empty vector
- a = i:k:n makes the vector with the step k and the last value i + k*fix((n-1)/k) the function fix(l) returns the nearest integer number to l towards 0
- when k < 0 we get the vector of decaying values
- to get the column vector b transpose a vector b = a'
- vector dimension is defined by its length; to get length of a use length(a) function (one can use also size(a) function defined below)
- a scalar is a vector of 1 × 1 size
- Matrix is a mathematical object being a table with numbers. To describe its dimension number of rows (e. g. n) and columns (e. g. m) must be given. Thus the size of matrix is defined by the pair of numbers n × m. The number of rows is called dimension 1 and the number of column is called dimension 2. This is the simplest form of a table containing numbers. However, tables can have more than 2 dimensions. Then their sizes are described by a set of numbers: n × m × l × …
- to create a table A
- one can explicitly write numbers into its rows and columns
- or concatenate vectors along its 1 or 2 dimension
A = [a; b] dim = 1 and A = [a, b] dim = 2 (or use cat(dim, a, b) function)
- to get size of matrix (2 or more numbers) use size(A) function
- to get rank of A use rank(A) function; the rank of matrix is defined as the highest degree of a sub-matrix of non-zero determinant
- to get trace of A use trace(A) function; the trace of matrix is defined as the sum of its elements located at its main diagonal
- to get the vector being k-th diagonal of matrix A use diag(A, k) function; when k = 0 the function returns the main matrix diagonal
- some special cases
- to generate a matrix with vector a on its diagonal use diag(a, 0) function
- to generate a matrix with vector a on its k-th sup-diagonal use diag(a, k) function
- to generate a matrix with vector a on its k-th sub-diagonal use diag(a, -k) function
- to generate matrix of ones use ones(n,n) function
- to generate matrix of zeros use zeros(n,n) function
- to generate matrix of n × m size with ones on the main diagonal use eye(n, m) function
- Getting elements of matrix or vector.
- Operator : can be also used to pick up whole columns or rows of matrix or vector
A(:,i) - takes i-th column of A matrix
A(i,:) - takes i-th row of A matrix
A(:, i:n) - takes columns from i-th to n-th
A(i:n, :) - takes rows from i-th to n-th
- A(:) makes one column vector from A matrix by putting all columns (from first to the last) from the matrix A in one column vector.
- A(i:n) makes one row vector from A matrix by putting elements from the i-th to the n-th from the matrix A in one row.
Elements in a table are enumerated along columns as they form the column vector described above.
- to transpose A matrix (or vector) use A' or transpose(A) function
- to multiply two matrices A and B the number of columns of the first one should equal to the number of rows of the second one: A * B
- .* denotes matrices multiplication. The result of A.*B is a matrix of elements aij*bij, i. e. the elements of the A matrix are multiplied by the elements of B matrix, respectively. Both A and B must have the same sizes or one of them can be a scalar.
- when A is a square matrix A^n where n is a scalar denotes n-th power of A
- A.^n where n is a scalar gives the matrix of elements anij
- when A and C are matrices of the same size then A.^C is a matrix of elements aijcij
- when matrix A is square its determinant can be found: det(A)
- when matrix is square and their determinant differs from 0 then the inverse matrix to the A matrix exists and could be obtained by the inv(A) function
- if one needs to find the inverse matrix due to solve the equation
inv(A) * B it is better to use the left division operator A \ B (it is true also for rectangular matrices under condition that A and B have the same number of rows; why? see below)
A pseudo-inverse matrix Ag to the matrix A of n × m size is any matrix of the m × n size which fulfilled the following condition:
A AgA = A
but the pseudo-inverse matrix Ah to the matrix A of n × m size is the matrix of the m × n size which fulfilled the following conditions:
A AhA = A
for matrices U of n × n and V of m × m.
Ah = U AT = AT V
To compute the pseudo–inverse matrix one can make use of
If the matrix A ∈ ℜm×n has the rank r then it can be represented as product of two matrices B ∈ ℜm×r and C∈ℜr×n that have the rank r each
A = BC
rank B = rank C = r
- using the right division operator A / B is equivalent to the A * inv(B) (it is true also for rectangular matrices under condition that A and B have the same number of columns)
- adding two matrices: C = A + B means that cij = aij + bij where i = 1...n and j = 1...m
- subtract two matrices: C = A - B means that cij = aij - bij where i = 1...n and j = 1...m
- .\ denotes left matrices division. The result of A.\B is a matrix of elements bij/aij, i. e. the elements of the B matrix are divided by the elements of A matrix, respectively. Both A and B must have the same sizes or one of them can be a scalar.
- ./ denotes right matrices division. The result of A./B is a matrix of elements aij/bij, i. e. the elements of the A matrix are divided by the elements of B matrix, respectively. Both A and B must have the same sizes or one of them can be a scalar.
- to extract the upper triangular matrix from the A use triu(A)
- to extract the lower triangular matrix from the A use tril(A)
- to rotate the A matrix of 90 degrees use rot90(A) function
- to flip once the matrix A up and down use flipud(A) function
- to flip once the matrix A left and right use fliplr(A) function
- to flip the matrix along 1 or 2 dimension use flipdim(A, dim) function
- to replicate matrix A to get a block matrix with size m by n use repmat(A, [m, n] ) function
- to form a new matrix from the A matrix with a new size m by n use reshape(A, m, n) function
Assume that a
is a vector
prod(a) function gives the product of all vector elements
sum(a) function gives the sum of all vector elements
- cumprod(a) function gives the vector of subsequent products of a elements
- cumsum(a) function gives the vector of subsequent sums of a elements
Last update: June 10, 2020
© 2013-2020 taketechease.com