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 objectoriented 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 MFile
 Vectors and Matrices
 Logical Operators
 Conditional Instructions
 Loops
 Matrix Equations
 Elementary
 Gauss Elimination Method
 Cholesky Factorisation
 Least Squares Problem
 2D Graphical Data Representation
 Complex Numbers
 Polynomials
 Functions
 Script Functions
 Anonymous Functions
 Inline Functions
 Other MATLAB/Octave Data Types
 Multi – Dimensional Arrays
 Errors
 Warnings
 Dialog Windows (MATLAB)
 UI Objects (MATLAB)
 3D Graphical Data Representation
 Graphics 3D
 Trimesh and Delaunay Triangulation
 Animation
 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.
Generation

Vector is a mathematical object usually used to describe a point position.
In n – dimensional space it has the structure: a = [a_{1}, a_{2}, a_{3}, …, a_{n}] where a_{i} denotes the ith coordinate of a being the vector projection on the ith 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((n1)/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 submatrix of nonzero 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 kth 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 kth supdiagonal use diag(a, k) function
 to generate a matrix with vector a on its kth subdiagonal 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 ith column of A matrix
A(i,:)  takes ith row of A matrix
A(:, i:n)  takes columns from ith to nth
A(i:n, :)  takes rows from ith to nth
 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 ith to the nth from the matrix A in one row.
Elements in a table are enumerated along columns as they form the column vector described above.
The
mfile with exercises.
Operations
 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 a_{ij}*b_{ij}, 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 nth power of A
 A.^n where n is a scalar gives the matrix of elements a^{n}_{ij}
 when A and C are matrices of the same size then A.^C is a matrix of elements a_{ij}^{cij}
 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 pseudoinverse matrix A^{g} to the matrix A of n × m size is any matrix of the m × n size which fulfilled the following condition:
A A^{g}A = A
but the pseudoinverse matrix A^{h} to the matrix A of n × m size is the matrix of the m × n size which fulfilled the following conditions:
A A^{h}A = A
A^{h} = U A^{T} = A^{T} V
for matrices U of n × n and V of m × m.
To compute the pseudo–inverse matrix one can make use of
Lemma:
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 c_{ij} = a_{ij} + b_{ij} where i = 1...n and j = 1...m
 subtract two matrices: C = A  B means that c_{ij} = a_{ij}  b_{ij} where i = 1...n and j = 1...m
 .\ denotes left matrices division. The result of A.\B is a matrix of elements b_{ij}/a_{ij}, 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 a_{ij}/b_{ij}, 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)
function
 to extract the lower triangular matrix from the A use tril(A)
function
 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 BLOCK 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
The
mfile with exercises.
Useful Functions
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
The
mfile with exercises.
Last update: January 2, 2021
© 20132021 taketechease.com
Privacy Policy
Terms of Use