Scilab/C2/Vector-Operations/English

From Script | Spoken-Tutorial
Jump to: navigation, search

Title of script: Vector Operations

Author: Shalini Shrivastava

Keywords:


Visual Cue
Narration
Slide 1

[Title slide]

Welcome to the spoken tutorial on Vector Operations
Slide 2

[Objectives slide]

Objectives:

In this tutorial we will learn how to,


Define a vector.

Calculate length of a vector.

Perform mathematical operations on Vectors such as addition,subtraction and multiplication.

Define a matrix.

Calculate size of a matrix.

Perform mathematical operations on Matrices such as addition, subtraction and multiplication.



Slide I will use Scilab 5.2.2 version and Windows 7 for demonstration.
Slide 3

[Prerequisites]


* Scilab should be installed on your system.
  • You should have listened to the Spoken Tutorial on Getting started with Scilab.
  • You should have Basic knowledge about Vectors and Matrices.



Launch Scilab Click on Scilab shortcut icon on your Desktop to launch Scilab.


This will open the Scilab console window. Notice that the cursor is on the command prompt.


I suggest that you practice this tutorial in Scilab simultaneously while pausing the video at regular intervals of time.

Scilab Console Let us start by defining a vector.

This can be done in two ways:

by using spaces

-->p = [1 2 3]

p =


1. 2. 3.

or using commas.

-->q = [2,3,4]

q =


2. 3. 4.

We can find the length of a vector p by the command

-->length(p)

ans =


3.

We can perform various mathematical operations on vectors such as

Addition of vectors:

-->p + q

ans =


3. 5. 7.


Substraction of vectors

-->q - p

ans =


1. 1. 1.


and so on.

Transpose of a vector can be found using apostrophe (also known as single-quote).

-->p

ans =

1.

2.

3.

We can calculate p-transpose times q:

-->p'*q

ans =

2. 3. 4.

4. 6. 8.

6. 9. 12.


The command p times q-transpose gives a scalar:

-->p*q

ans =

20.

Please pause the tutorial now and attempt exercise number one given with the video
Slide 5

[Execise Slide]

Define two vectors A,B with 1,5,8,19 and 19,8,5,1

elements respectively.

Calculate A’*B-B’*A

Calculate A*A’+B*B’

Scilab console Now we will see how to define a matrix.

Elements of a row of a matrix, can be defined using spaces or commas similar to that shown for a vector

For example, define a 2 by 3 matrix P by typing

-->P = [1 2 3;4 5 6]

P =

1. 2. 3.

4. 5. 6.

Note that Semicolon is used for defining the next row of the matrix.

Recall that Scilab is case sensitive.

Here variable P used to define matrix is in upper case.

Which is different from small p that was a vector.

Would you want to check what small p is at this point?

We will now see how to find the size of a Matrix using the “size” command.

-->[row, col] = size(P)

col =

3.

row =

2.

Note that the length command will give the total number of elements in the matrix

---> length(P)

ans =

6

The transpose command works for matrices as well as shown here :

-->P'

ans =

1. 4.

2. 5.

3. 6.


Let us now define a 2 by 3 matrix Q:

-->Q = [1 5 3;2 4 8]

Q =

1. 5. 3.

2. 4. 8.

Let us also recall P once more:

We can carry out calculations involving P and Q, just as we do in mathematics.

For example, let us calculate:

-->E = 2*P + 3*Q

E =


5. 19. 15.

14. 22. 36.

You may want to verify whether these calculations are correct.

Slide 5 (Exercise) Please pause the tutorial now and attempt exercise number two given with the video

In Scilab Console, enter the following Matrices


A =[1 ½ ; 1/3 ¼ ; 1/5 1/6]

B =[5 2]

C =[4 5/4 9/4 ; 1 2 3]


Compute each of the following and figure out the errors yourself, if any.

A∗C −C ∗A

2∗C −6∗A

(2 ∗ C − 6 ∗ A ) ∗ B

(2 ∗ C − 6 ∗ A ) ∗ C

Slide Summary

In this tutorial, we have learnt how to

Define a vector using spaces or commas.

Calculate length of a vector using the length() function.

Find the transpose of vector or matrix using apostrophe.

Define a matrix by using space/comma to separate the

columns and semicolon to separate the rows.

Find size of a matrix using size() function.

Perform mathematical operations on vectors and matrices.

Slide 7 This brings us to the end of this spoken tutorial on Matrix operations Part1.


There are many other functions in matrix operations which will be covered in Matrix Operations Part2.

Keep watching the Scilab links.

This spoken tutorial has been created by the Free and Open Source Software in Science and Engineering Education (FOSSEE).

More information on the FOSSEE project could be obtained from http://fossee.in or http://scilab.in

Supported by the National Mission on Eduction through ICT, MHRD, Government of India.

For more information, visit:

http://spoken-tutorial.org/NMEICT-Intro

This is Anuradha Amrutkar from IIT Bombay signing off.

Good bye

Contributors and Content Editors

Chandrika, PoojaMoolya