Scilab/C2/Matrix-Operations/Gujarati

From Script | Spoken-Tutorial
Revision as of 10:06, 19 November 2013 by Krupali (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Time Narration
00.03 Welcome to the spoken tutorial on Matrix Operations.
00.07 At the end of this spoken tutorial, you will be able to:
00.10 Access the elements of Matrix
00.13 Determine the determinant, inverse and eigen values of a matrix.
00.19 Define special matrices.
00.23 Perform elementary row operations.
00.25 Solve the system of “linear equations”.
00.29 The preequisites are
00.31 Scilab should be installed on your system.
00.34 You should have listened to the Spoken Tutorial: Getting started with Scilab and 'Vector Operations.
00.42 I am using Windows 7 operating system and Scilab 5.2.2 for demonstration.
00.50 Start Scilab by double-clicking on the Scilab icon present on yourDesktop.
00.59 It is suggested that the user should practice this tutorial in Scilab simultaneously while pausing the video at regular intervals of time.
01.09 Recall that in the Spoken Tutorial, 'Vector Operations',
01.12 matrix E was defined as E = [5 19 15;8 22 36]and press enter
01.37 Let us now see how to address individual elements of a matrix, separately.
01.42 To access the element in the first row and second column, type: E(1,2) and press enter
01.56 It is easy to extract an entire row or an entire column of a matrix in Scilab .
02.03 For example, first row of E can be obtained using the following command: E1 = E(1,:) and press enter
02.24 The command returns all the elements of the first row in the order of their appearance in the row.
02.30 Colon, when used alone, refers to all the elements of row or column, depending upon whether it appears as a first or a second entry respectively inside the bracket.
02.44 Also, any subset of a matrix can be extracted using a colon (“:”).
02.49 For example, the set of elements starting from second to third columns of E can be obtained using the following command:
03.01 -->E2 = E(:,2:3) close the bracket and press enter
03.18 In the above, the second entry in the bracket, that is, "2 colon 3" makes a reference to elements from column 2 to column 3.
03.28 If the size of the matrix is not known $ symbol can be used to extarct the last row or column of that matrix.
03.38 For example to extract all rows of the last column of the matrix E, we will type
03.46 --->E last column = E(:,$) close the bracket and press enter
04.06 Now, let us learn how to calculate the determinant of a square matrix using the command “det”
04.13 Recall that in the Spoken Tutorial, Vector Operations, we had defined A as
04.20 A=[1 2 - 1; - 2 - 6 4; - 1 - 3 3] close the square bracket and press enter
04.50 Let us calculate the determinant of A by the command det(A) and press Enter.
05.00 To calculate the inverse and the eigenvalues of a matrix, the commands, “inv” and “spec” respectively, can be used.
05.09 For example: inv(A) gives the inverse of A and spec(A) gives the eigen values of A
05.29 See 'help spec' to see how eigenvectors can also be obtained using this command.
05.35 Square or cube of a square matrix A can be calculated by simply typing A^2 or A^3 respectively.
05.52 A caret symbol is used to raise a matrix to power, like in ordinary arithmetic operations. In our keyboard, it is obtained by pressing shift+6.
06.05 Please pause the tutorial now and attempt exercise number one given with the video.
06.18 Certain special matrices can also be created in Scilab:
06.24 For example a matrix of zeros with 3 rows and 4 columns can be created using “zeros” command
06.36 zeros(3,4) and press enter
06.48 A matrix of all ones can be created with “ones” command as follows
06.53 ones(2,4) gives a matrix of all ones
07.02 It is easy to create an identity matrix using “eye” command:
07.07 eye(4,4) gives a 4 by 4 identity matrix
07.17 A user may need a matrix consisting of pseudo random numbers. It can be generated using the “rand” command as follows:
07.25 p=rand(2,3) and press enter
07.39 In linear systems, one of the important sets of operations a user carries out on matrices are the elementary row and column operations.
07.55 These operations involve executing row operations on a matrix to make entries below a nonzero number, zero. This can be done easily in Scilab.
08.08 Recall that in the Spoken Tutorial,Vector Operations, we had defined the matrix P as follows.
08.18 P = [1 2 3;4 11 6]close the square bracket and press enter
08.34 Let us consider an example where the element in the second row, first column is to be transformed to zero using elementary row and column operation.
08.45 The operation can be executed by multiplying the first row by 4 and subtracting it from the second row as in the following command:
08.57 P(2,:) = P(2,:) - 4*P(1,:) and press enter
09.29 The procedure can be extended to larger systems and to other forms of elementary column operations.
09.35 Rows and columns can be easily appended to matrices.
09.39 For example, to append a row containing [5 5 -2] to P, the following command is used:
09.49 T = [P; [5 5 -2]] close both the square bracket and press enter
10.15 The semicolon after P states that the anything after it should go to the next row. '
10.20 This is expected in the way a matrix is defined.
10.24 As an exercise, please pause here and check if the brackets around the new row, in the command just executed, are really required.
10.34 Matrix notations are used while solving equations.
10.41 Let us solve the following set of linear equations:
10.44 x1 + 2 x2 − x3 = 1
10.48 − 2 x1 − 6 x2 + 4 x3 = − 2
10.54 − x1 − 3 x2 + 3 x3 = 1
11.00 The above set of equations can be written in the Ax = b form.
11.05 The solution is then given as inverse of A times b
11.11 Let us solve the set of equations.
11.15 A is defined as A = [1 2 -1;-2 -6 4;-1 -3 3] close the square bracket and press enter
11.46 B can be defined as b = [1;-2;1]close the square bracket and press enter
12.04 The solution, x, can be obtained using x = inv(A)*b
12.20 It is worth noting that it is a small letter 'i' in the command, 'inv'.
12.27 Alternatively, the same result can be achieved using a backslash operation in Scilab.
12.33 Lets do this in Scilab x = A\b and press enter.
12.45 It gives the same result. Type "help backslash" and "help inv" in Scilab to know more about individual advantages and disadvantages.
12.55 The integrity of the solution can be verified by back substitution, that is, by calculating Ax-b:
13.05 A*x-b
13.10 The above exercise verifies the result achieved earlier.
13.14 It is possible that in some systems the above verification exercise may not yield a matrix with *exact* zeros as its elements due to intermediate floating point operations.
13.27 However, one will indeed get a very small number, typically of the order of 10 raised to -16
13.35 Please pause the tutorial now and attempt exercise number two given with the video.
13.49 This brings us to the end of this spoken tutorial on Matrix Operation.
13.54 There are many other functions in Scilab which will be covered in other spoken tutorials.
13.59 Keep watching the Scilab links.
14.02 In this tutorial we have learnt
14.04 To access the element of the matrix using the colon operator
14.08 Calculate the inverse of a matrix using the 'inv' command or by backslash
14.14 Calculate the derterminant of matrix using 'det' command.
14.19 Calculate eigen values of a matrix using 'spec' command.
14.24 Define a matrix having all the elements one, Null Matrix,
14.29 Identity matrix and a matrix with random elements by using functions ones(), zeros(), eye(), rand() respectively
14.39 Solve the system of linear equations.
14.43 This spoken tutorial has been created by the Free and Open Source Software in Science and Engineering Education(FOSSEE).
14.51 More information on the FOSSEE project could be obtained from http://fossee.in or [1]
14.59 Supported by the National Mission on Eduction through ICT, MHRD, Government of India.
15.05 For more information, visit: http://spoken-tutorial.org/NMEICT-Intro
15.15 This is Anuradha Amrutkar from IIT Bombay signing off.
Thank you for joining. Goodbye.

Contributors and Content Editors

Gaurav, Jyotisolanki, Krupali, Pratik kamble