Vector and Matrix Operations in Scilab

Matrix Operations in Scilab is very easy before starting matrix operations let’s first discuss vectors.

You can easily perform add, subtraction, multiplication, calculation of eigenvalue and Eigenvectors, finding the inverse of the matrix, calculating linear equations and many more operations are easy with Scilab.

What is Vector in Scilab

We can create a vector in Scilab as below. Elements can be separated by, or space

Finding length of vector   

To find the length of vector length () method is used and the name of the vector is passed as an argument.

Transpose of a vector

To find the transpose of a vector used ‘  with vector.

Adding a number in vector

To add a scalar number in vector simple addition is done and addition is done with each element of vector.

Subtracting a number in vector

Subtracting scalar number from each element following statement is used.

Addition of two vectors

To add to vector store each one in a variable and perform add operation as below.

Subtraction of two vectors

It is also similar to variable subtraction

Matrix and matrices operations in scilab

Matrix is a rectangular arrangement of elements.

Creating matrix in scilab

 Accessing elements in Matrix Scilab

Scilab uses 1 based indexing to access elements.

To access all elements of a row : is used

a(:,: ) has the same meaning as a

here first : represents column and second : represents row,

To find second and third row of each column a (:,2:3)

Accessing the last element of matrix

a($)  this will last element of matrix

Finding last element of first column

Finding last element of each column

Adding a new row to matrix

Lets add a new row in matrix.

Finding size of matrix in Scilab

To find the size of matrix the size() is used.

with size to gets row and columns

it can be used like

[row,column]=size(a)

here row and columns are stored in row and column variable

Finding square and cube of matrix

To find square and qube of matrix we have to use power operator

To find the power a square matrix is needed.

Addition and subtraction of matrix

Addition and subtraction of matrix is similar to add or subtract variables.

Matrix multiplication in scilab

For multiplication of the matrix number of rows of the first matrix should match the number of columns of the second matrix.

Calculating the determinant of matrix

Let’s consider a matrix to find its determinant.

To find the determinant use det()

Inverse of matrix

To find the inverse of matrix inv() is used.

Eigenvalues of square matrix

To find the eigenvalue of matrix spec() is used.

Functions related to matrix creation

To create different matrix following functions are used.

Creating zero matrix of 4×4

Creating ones matrix of 4×4

Creating identity matrix if 3×3

Creating random matrix of 3×4

Solving linear equation using matrices

Lets see how to solve linear equation in scilab.

  1. Get the equation.
  2. Represent data in matrix form
  3. Calculate inv(a)*b
  4. Result will be solution for linear equation
How do you create an identity matrix of 3 by 3 in scilab?

To create an identity matrix we use function eye(m,n). To create 3 by 3 identity matrix use eye(3,3).

Read More

Scilab Basics

Reference

Matrix operations