Difference between revisions of "Scilab/C2/Matrix-Operations/English-timed"
From Script | Spoken-Tutorial
Line 1: | Line 1: | ||
{| Border=1 | {| Border=1 | ||
− | | | + | |'''Time''' |
− | | | + | |'''Narration''' |
|- | |- | ||
− | | 00 | + | | 00:02 |
| | Welcome to the spoken tutorial on Matrix Operations. | | | Welcome to the spoken tutorial on Matrix Operations. | ||
Line 13: | Line 13: | ||
|- | |- | ||
− | |00 | + | |00:06 |
| | At the end of this spoken tutorial, you will be able to: | | | At the end of this spoken tutorial, you will be able to: | ||
Line 19: | Line 19: | ||
|- | |- | ||
− | | 00 | + | | 00:10 |
| | Access the elements of Matrix | | | Access the elements of Matrix | ||
Line 25: | Line 25: | ||
|- | |- | ||
− | | 00 | + | | 00:13 |
| |Determine the determinant, inverse and eigen values of a matrix. | | |Determine the determinant, inverse and eigen values of a matrix. | ||
Line 31: | Line 31: | ||
|- | |- | ||
− | | 00 | + | | 00:18 |
| |Define special matrices. | | |Define special matrices. | ||
Line 37: | Line 37: | ||
|- | |- | ||
− | | 00 | + | | 00:22 |
| | Perform elementary row operations. | | | Perform elementary row operations. | ||
Line 43: | Line 43: | ||
|- | |- | ||
− | | 00 | + | | 00:25 |
| | Solve the system of “linear equations”. | | | Solve the system of “linear equations”. | ||
Line 49: | Line 49: | ||
|- | |- | ||
− | |00 | + | |00:28 |
| | The prerequisites are | | | The prerequisites are | ||
Line 55: | Line 55: | ||
|- | |- | ||
− | | 00 | + | | 00:30 |
| |Scilab should be installed on your system. | | |Scilab should be installed on your system. | ||
Line 61: | Line 61: | ||
|- | |- | ||
− | | 00 | + | | 00:34 |
| |''You should have listened to the Spoken Tutorial: Getting started with Scilab and '''Vector Operations. | | |''You should have listened to the Spoken Tutorial: Getting started with Scilab and '''Vector Operations. | ||
Line 67: | Line 67: | ||
|- | |- | ||
− | | 00 | + | | 00:42 |
| |I am using Windows 7 operating system and Scilab 5.2.2 for demonstration. | | |I am using Windows 7 operating system and Scilab 5.2.2 for demonstration. | ||
Line 73: | Line 73: | ||
|- | |- | ||
− | | 00 | + | | 00:50 |
| | Start Scilab by double-clicking on the Scilab icon present on your Desktop. | | | Start Scilab by double-clicking on the Scilab icon present on your Desktop. | ||
Line 79: | Line 79: | ||
|- | |- | ||
− | | 00 | + | | 00:59 |
| |It is suggested that the user should practice this tutorial in Scilab simultaneously while pausing the video at regular intervals of time. | | |It is suggested that the user should practice this tutorial in Scilab simultaneously while pausing the video at regular intervals of time. | ||
Line 85: | Line 85: | ||
|- | |- | ||
− | | 01 | + | | 01:08 |
| | Recall that in the Spoken Tutorial, 'Vector Operations', | | | Recall that in the Spoken Tutorial, 'Vector Operations', | ||
Line 91: | Line 91: | ||
|- | |- | ||
− | | 01 | + | | 01:12 |
| | matrix E was defined as E is equal to open square bracket 5 space 19 space 15 semicolon 8 space 22 space 36 close the square bracket and press enter | | | matrix E was defined as E is equal to open square bracket 5 space 19 space 15 semicolon 8 space 22 space 36 close the square bracket and press enter | ||
Line 97: | Line 97: | ||
|- | |- | ||
− | | 01 | + | | 01:37 |
| |Let us now see how to address individual elements of a matrix, separately. | | |Let us now see how to address individual elements of a matrix, separately. | ||
Line 103: | Line 103: | ||
|- | |- | ||
− | | 01 | + | | 01:42 |
| |To access the element in the first row and second column, type E into bracket 1,2 and press enter | | |To access the element in the first row and second column, type E into bracket 1,2 and press enter | ||
Line 109: | Line 109: | ||
|- | |- | ||
− | | 01 | + | | 01:56 |
| | It is easy to extract an entire row or an entire column of a matrix in Scilab . | | | It is easy to extract an entire row or an entire column of a matrix in Scilab . | ||
Line 115: | Line 115: | ||
|- | |- | ||
− | | 02 | + | | 02:03 |
| |For example, first row of E can be obtained using the following command: E1 = E into bracket 1 comma colon and press enter | | |For example, first row of E can be obtained using the following command: E1 = E into bracket 1 comma colon and press enter | ||
Line 121: | Line 121: | ||
|- | |- | ||
− | | 02 | + | | 02:23 |
| |The command returns all the elements of the first row in the order of their appearance in the row. | | |The command returns all the elements of the first row in the order of their appearance in the row. | ||
Line 127: | Line 127: | ||
|- | |- | ||
− | | 02 | + | | 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. | | |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. | ||
Line 133: | Line 133: | ||
|- | |- | ||
− | | 02 | + | | 02:44 |
| | Also, any subset of a matrix can be extracted using a colon (“:”). | | | Also, any subset of a matrix can be extracted using a colon (“:”). | ||
Line 139: | Line 139: | ||
|- | |- | ||
− | | 02 | + | | 02:49 |
| |For example, the set of elements starting from second to third columns of E can be obtained using the following command: | | |For example, the set of elements starting from second to third columns of E can be obtained using the following command: | ||
Line 145: | Line 145: | ||
|- | |- | ||
− | | 03 | + | | 03:00 |
| E2 = E of colon comma 2 colon 3 close the bracket and press enter | | E2 = E of colon comma 2 colon 3 close the bracket and press enter | ||
Line 151: | Line 151: | ||
|- | |- | ||
− | | 03 | + | | 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. | | |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. | ||
Line 157: | Line 157: | ||
|- | |- | ||
− | |03 | + | |03:28 |
| | If the size of the matrix is not known $ (dollar ) symbol can be used to extarct the last row or column of that matrix. | | | If the size of the matrix is not known $ (dollar ) symbol can be used to extarct the last row or column of that matrix. | ||
Line 163: | Line 163: | ||
|- | |- | ||
− | | 03 | + | | 03:38 |
| |For example to extract all rows of the last column of the matrix E, we will type | | |For example to extract all rows of the last column of the matrix E, we will type | ||
Line 169: | Line 169: | ||
|- | |- | ||
− | | 03 | + | | 03:46 |
| Elast col= E into brackets colon comma dollar sign close the bracket and press enter | | Elast col= E into brackets colon comma dollar sign close the bracket and press enter | ||
Line 175: | Line 175: | ||
|- | |- | ||
− | | 04 | + | | 04:06 |
| |Now, let us learn how to calculate the determinant of a square matrix using the command “det” | | |Now, let us learn how to calculate the determinant of a square matrix using the command “det” | ||
Line 181: | Line 181: | ||
|- | |- | ||
− | | 04 | + | | 04:13 |
| |Recall that in the Spoken Tutorial, Vector Operations, we had defined A as | | |Recall that in the Spoken Tutorial, Vector Operations, we had defined A as | ||
Line 187: | Line 187: | ||
|- | |- | ||
− | | 04 | + | | 04:19 |
| |A = open square bracket 1 space 2 space minus 1 semicolon -2 space - 6 space 4 semicolon -1 space -3 space 3 close the square bracket and press enter | | |A = open square bracket 1 space 2 space minus 1 semicolon -2 space - 6 space 4 semicolon -1 space -3 space 3 close the square bracket and press enter | ||
Line 193: | Line 193: | ||
|- | |- | ||
− | | 04 | + | | 04:50 |
| |Let us calculate the determinant of A by the command det of A and press Enter. | | |Let us calculate the determinant of A by the command det of A and press Enter. | ||
Line 199: | Line 199: | ||
|- | |- | ||
− | | 05 | + | | 05:00 |
|| To calculate the inverse and the eigenvalues of a matrix, the commands, “inv” and “spec” respectively, can be used. | || To calculate the inverse and the eigenvalues of a matrix, the commands, “inv” and “spec” respectively, can be used. | ||
Line 205: | Line 205: | ||
|- | |- | ||
− | | 05 | + | | 05:09 |
|| For example: inv of A gives the inverse of A and spec of A gives the eigen values of matrix A | || For example: inv of A gives the inverse of A and spec of A gives the eigen values of matrix A | ||
Line 211: | Line 211: | ||
|- | |- | ||
− | | 05 | + | | 05:29 |
| |See 'help spec' to see how eigenvectors can also be obtained using this command. | | |See 'help spec' to see how eigenvectors can also be obtained using this command. | ||
Line 217: | Line 217: | ||
|- | |- | ||
− | | 05 | + | | 05:35 |
| |Square or cube of a square matrix A can be calculated by simply typing A square or A cube '''respectively'''. | | |Square or cube of a square matrix A can be calculated by simply typing A square or A cube '''respectively'''. | ||
Line 223: | Line 223: | ||
|- | |- | ||
− | | 05 | + | | 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. | | |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. | ||
Line 229: | Line 229: | ||
|- | |- | ||
− | | 06 | + | | 06:05 |
| |Please pause the tutorial now and attempt the exercise number one given with the video. | | |Please pause the tutorial now and attempt the exercise number one given with the video. | ||
Line 235: | Line 235: | ||
|- | |- | ||
− | | 06 | + | | 06:17 |
| | Certain special matrices can also be created in Scilab: | | | Certain special matrices can also be created in Scilab: | ||
Line 241: | Line 241: | ||
|- | |- | ||
− | | 06 | + | | 06:24 |
| |For example a matrix of zeros with 3 rows and 4 columns can be created using “zeros” command | | |For example a matrix of zeros with 3 rows and 4 columns can be created using “zeros” command | ||
Line 247: | Line 247: | ||
|- | |- | ||
− | | 06 | + | | 06:36 |
| |zeros into bracket 3 comma 4 and press enter | | |zeros into bracket 3 comma 4 and press enter | ||
Line 253: | Line 253: | ||
|- | |- | ||
− | | 06 | + | | 06:47 |
| |A matrix of all ones can be created with “ones” command as follows | | |A matrix of all ones can be created with “ones” command as follows | ||
Line 259: | Line 259: | ||
|- | |- | ||
− | | 06 | + | | 06:53 |
| |ones into bracket 2 comma 4 gives a matrix of all ones | | |ones into bracket 2 comma 4 gives a matrix of all ones | ||
Line 265: | Line 265: | ||
|- | |- | ||
− | | 07 | + | | 07:01 |
| |It is easy to create an identity matrix using the “eye” command: | | |It is easy to create an identity matrix using the “eye” command: | ||
Line 271: | Line 271: | ||
|- | |- | ||
− | | 07 | + | | 07:07 |
| ' e y e' of 4 comma 4 gives a 4 by 4 identity matrix | | ' e y e' of 4 comma 4 gives a 4 by 4 identity matrix | ||
Line 277: | Line 277: | ||
|- | |- | ||
− | | 07 | + | | 07:16 |
| |A user may need a matrix consisting of pseudo random numbers. It can be generated using the “rand” command as follows: | | |A user may need a matrix consisting of pseudo random numbers. It can be generated using the “rand” command as follows: | ||
Line 283: | Line 283: | ||
|- | |- | ||
− | | 07 | + | | 07:25 |
| |p=rand into bracket 2, 3 and press enter | | |p=rand into bracket 2, 3 and press enter | ||
Line 289: | Line 289: | ||
|- | |- | ||
− | | 07 | + | | 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. | | | In linear systems, one of the important sets of operations a user carries out on matrices are the elementary row and column operations. | ||
Line 295: | Line 295: | ||
|- | |- | ||
− | | 07 | + | | 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. | | |These operations involve executing row operations on a matrix to make entries below a nonzero number, zero. This can be done easily in Scilab. | ||
Line 301: | Line 301: | ||
|- | |- | ||
− | | 08 | + | | 08:07 |
| |Recall that in the Spoken Tutorial,Vector Operations, we had defined the matrix P as follows. | | |Recall that in the Spoken Tutorial,Vector Operations, we had defined the matrix P as follows. | ||
Line 307: | Line 307: | ||
|- | |- | ||
− | | 08 | + | | 08:17 |
| |P = open square bracket 1 space 2 space 3 semicolon 4 space 11 space 6 close the square bracket and press enter | | |P = open square bracket 1 space 2 space 3 semicolon 4 space 11 space 6 close the square bracket and press enter | ||
Line 313: | Line 313: | ||
|- | |- | ||
− | | 08 | + | | 08:33 |
| |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. | | |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. | ||
Line 319: | Line 319: | ||
|- | |- | ||
− | | 08 | + | | 08:44 |
| |The operation can be executed by multiplying the first row by 4 and subtracting it from the second row as in the following command: | | |The operation can be executed by multiplying the first row by 4 and subtracting it from the second row as in the following command: | ||
Line 325: | Line 325: | ||
|- | |- | ||
− | | 08 | + | | 08:56 |
| |P into bracket 2 comma colon is equal to P into bracket 2 comma colon minus 4 multiplied by P into bracket 1 comma colon and press enter | | |P into bracket 2 comma colon is equal to P into bracket 2 comma colon minus 4 multiplied by P into bracket 1 comma colon and press enter | ||
Line 331: | Line 331: | ||
|- | |- | ||
− | | 09 | + | | 09:28 |
| The procedure can be extended to larger systems and to other forms of elementary column operations. | | The procedure can be extended to larger systems and to other forms of elementary column operations. | ||
Line 337: | Line 337: | ||
|- | |- | ||
− | | 09 | + | | 09:35 |
| |Rows and columns can be easily appended to matrices. | | |Rows and columns can be easily appended to matrices. | ||
Line 343: | Line 343: | ||
|- | |- | ||
− | | 09 | + | | 09:39 |
| |For example, to append a row containing the elements [5 5 -2] to P, the following command is used: | | |For example, to append a row containing the elements [5 5 -2] to P, the following command is used: | ||
Line 349: | Line 349: | ||
|- | |- | ||
− | |09 | + | |09:48 |
| |T = open square bracket P semicolon, open another square bracket write down the elements 5 5 -2 close both the square bracket and press enter | | |T = open square bracket P semicolon, open another square bracket write down the elements 5 5 -2 close both the square bracket and press enter | ||
Line 355: | Line 355: | ||
|- | |- | ||
− | | 10 | + | | 10:14 |
| |The semicolon after P states that anything after it should go to the next row. ' | | |The semicolon after P states that anything after it should go to the next row. ' | ||
Line 361: | Line 361: | ||
|- | |- | ||
− | | 10 | + | | 10:20 |
| |This is expected in the way a matrix is defined. | | |This is expected in the way a matrix is defined. | ||
Line 367: | Line 367: | ||
|- | |- | ||
− | | 10 | + | | 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. | | |As an exercise, please pause here and check if the brackets around the new row, in the command just executed, are really required. | ||
Line 373: | Line 373: | ||
|- | |- | ||
− | | 10 | + | | 10:34 |
| |Matrix notations are used while solving equations. | | |Matrix notations are used while solving equations. | ||
Line 379: | Line 379: | ||
|- | |- | ||
− | | 10 | + | | 10:40 |
|| Let us solve the following set of linear equations: | || Let us solve the following set of linear equations: | ||
Line 385: | Line 385: | ||
|- | |- | ||
− | | 10 | + | | 10:44 |
| |x1 + 2 x2 − x3 = 1 | | |x1 + 2 x2 − x3 = 1 | ||
Line 391: | Line 391: | ||
|- | |- | ||
− | | 10 | + | | 10:48 |
| |−2 x1 − 6 x2 + 4 x3 = −2 | | |−2 x1 − 6 x2 + 4 x3 = −2 | ||
Line 397: | Line 397: | ||
|- | |- | ||
− | | 10 | + | | 10:54 |
| |and − x1 − 3 x2 + 3 x3 = 1 | | |and − x1 − 3 x2 + 3 x3 = 1 | ||
Line 403: | Line 403: | ||
|- | |- | ||
− | | 11 | + | | 11:00 |
| |The above set of equations can be written in the Ax = b form. | | |The above set of equations can be written in the Ax = b form. | ||
Line 409: | Line 409: | ||
|- | |- | ||
− | | 11 | + | | 11:05 |
| | The solution is then given as inverse of A times b | | | The solution is then given as inverse of A times b | ||
Line 415: | Line 415: | ||
|- | |- | ||
− | | 11 | + | | 11:11 |
| |Let us solve the set of equations. | | |Let us solve the set of equations. | ||
Line 421: | Line 421: | ||
|- | |- | ||
− | | 11 | + | | 11:15 |
| |A is defined as A = open square bracket 1 space 2 space -1 semicolon -2 space -6 space 4 semicolon -1 space -3 space 3 close the square bracket and press enter | | |A is defined as A = open square bracket 1 space 2 space -1 semicolon -2 space -6 space 4 semicolon -1 space -3 space 3 close the square bracket and press enter | ||
Line 427: | Line 427: | ||
|- | |- | ||
− | | 11 | + | | 11:46 |
| |B can be defined as b is equal toSquare bracket 1 semicoln -2 semicolon 1 close the square bracket and press enter | | |B can be defined as b is equal toSquare bracket 1 semicoln -2 semicolon 1 close the square bracket and press enter | ||
Line 433: | Line 433: | ||
|- | |- | ||
− | | 12 | + | | 12:04 |
| |The solution, x, can be obtained using x = inv of A multiplied by b | | |The solution, x, can be obtained using x = inv of A multiplied by b | ||
Line 439: | Line 439: | ||
|- | |- | ||
− | | 12 | + | | 12:19 |
| |It is worth noting that it is a small letter 'i' in the command, 'inv'. | | |It is worth noting that it is a small letter 'i' in the command, 'inv'. | ||
Line 445: | Line 445: | ||
|- | |- | ||
− | | 12 | + | | 12:26 |
| |Alternatively, the same result can be achieved using a backslash operation in Scilab. | | |Alternatively, the same result can be achieved using a backslash operation in Scilab. | ||
Line 451: | Line 451: | ||
|- | |- | ||
− | | 12 | + | | 12:33 |
| |Lets do this in Scilab x is equal to A backslash b and press enter. | | |Lets do this in Scilab x is equal to A backslash b and press enter. | ||
Line 457: | Line 457: | ||
|- | |- | ||
− | | 12 | + | | 12:44 |
| |It gives the same result. Type "help backslash" and "help inv" in Scilab to know more about individual advantages and disadvantages. | | |It gives the same result. Type "help backslash" and "help inv" in Scilab to know more about individual advantages and disadvantages. | ||
Line 463: | Line 463: | ||
|- | |- | ||
− | | 12 | + | | 12:55 |
| |The integrity of the solution can be verified by back substitution, that is, by calculating Ax-b: | | |The integrity of the solution can be verified by back substitution, that is, by calculating Ax-b: | ||
Line 469: | Line 469: | ||
|- | |- | ||
− | |13 | + | |13:05 |
|A multiplied by x minus b | |A multiplied by x minus b | ||
Line 475: | Line 475: | ||
|- | |- | ||
− | | 13 | + | | 13:10 |
| |The above exercise verifies the result achieved earlier. | | |The above exercise verifies the result achieved earlier. | ||
Line 481: | Line 481: | ||
|- | |- | ||
− | | 13 | + | | 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. | | |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. | ||
Line 487: | Line 487: | ||
|- | |- | ||
− | | 13 | + | | 13:27 |
| |However, one will indeed get a very small number, typically of the order of 10 raised to -16 | | |However, one will indeed get a very small number, typically of the order of 10 raised to -16 | ||
Line 493: | Line 493: | ||
|- | |- | ||
− | | 13 | + | | 13:34 |
| Please pause the tutorial now and attempt exercise number two given with the video. | | Please pause the tutorial now and attempt exercise number two given with the video. | ||
Line 499: | Line 499: | ||
|- | |- | ||
− | | 13 | + | | 13:49 |
| This brings us to the end of this spoken tutorial on Matrix Operation. | | This brings us to the end of this spoken tutorial on Matrix Operation. | ||
Line 505: | Line 505: | ||
|- | |- | ||
− | | 13 | + | | 13:53 |
| |There are many other functions in Scilab which will be covered in other spoken tutorials. | | |There are many other functions in Scilab which will be covered in other spoken tutorials. | ||
Line 511: | Line 511: | ||
|- | |- | ||
− | | 13 | + | | 13:59 |
| Keep watching the Scilab links. | | Keep watching the Scilab links. | ||
Line 517: | Line 517: | ||
|- | |- | ||
− | | 14 | + | | 14:02 |
| |In this tutorial we have learnt | | |In this tutorial we have learnt | ||
Line 523: | Line 523: | ||
|- | |- | ||
− | | 14 | + | | 14:04 |
| | To access the element of the matrix using the colon operator | | | To access the element of the matrix using the colon operator | ||
Line 529: | Line 529: | ||
|- | |- | ||
− | | 14 | + | | 14:07 |
| | Calculate the inverse of a matrix using the 'inv' command or by backslash | | | Calculate the inverse of a matrix using the 'inv' command or by backslash | ||
Line 535: | Line 535: | ||
|- | |- | ||
− | | 14 | + | | 14:14 |
| |Calculate the derterminant of matrix using 'det' command. | | |Calculate the derterminant of matrix using 'det' command. | ||
Line 541: | Line 541: | ||
|- | |- | ||
− | | 14 | + | | 14:18 |
| |Calculate eigen values of a matrix using 'spec' command. | | |Calculate eigen values of a matrix using 'spec' command. | ||
Line 547: | Line 547: | ||
|- | |- | ||
− | | 14 | + | | 14:23 |
| |Define a matrix having all the elements one, Null Matrix, Identity matrix and a matrix with random elements by using functions ones(), zeros(), eye(), rand() respectively | | |Define a matrix having all the elements one, Null Matrix, Identity matrix and a matrix with random elements by using functions ones(), zeros(), eye(), rand() respectively | ||
Line 554: | Line 554: | ||
|- | |- | ||
− | | 14 | + | | 14:39 |
| |Solve the system of linear equations. | | |Solve the system of linear equations. | ||
Line 560: | Line 560: | ||
|- | |- | ||
− | | 14 | + | | 14:42 |
| |This spoken tutorial has been created by the Free and Open Source Software in Science and Engineering Education(FOSSEE). | | |This spoken tutorial has been created by the Free and Open Source Software in Science and Engineering Education(FOSSEE). | ||
Line 566: | Line 566: | ||
|- | |- | ||
− | | 14 | + | | 14:51 |
| |More information on the FOSSEE project could be obtained from http://fossee.in or http://scilab.in | | |More information on the FOSSEE project could be obtained from http://fossee.in or http://scilab.in | ||
Line 572: | Line 572: | ||
|- | |- | ||
− | | 14 | + | | 14:58 |
| | Supported by the National Mission on Eduction through ICT, MHRD, Government of India. | | | Supported by the National Mission on Eduction through ICT, MHRD, Government of India. | ||
Line 578: | Line 578: | ||
|- | |- | ||
− | | 15 | + | | 15:05 |
| | For more information, visit: http://spoken-tutorial.org/NMEICT-Intro | | | For more information, visit: http://spoken-tutorial.org/NMEICT-Intro | ||
Line 584: | Line 584: | ||
|- | |- | ||
− | | 15 | + | | 15:14 |
| |This is Anuradha Amrutkar from IIT Bombay signing off. | | |This is Anuradha Amrutkar from IIT Bombay signing off. | ||
Line 590: | Line 590: | ||
|- | |- | ||
− | |15 | + | |15:18 |
| |Thank you for joining. Goodbye. | | |Thank you for joining. Goodbye. | ||
|} | |} |
Revision as of 16:34, 10 July 2014
Time | Narration |
00:02 | Welcome to the spoken tutorial on Matrix Operations. |
00:06 | 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:18 | Define special matrices. |
00:22 | Perform elementary row operations. |
00:25 | Solve the system of “linear equations”. |
00:28 | The prerequisites are |
00:30 | 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 your Desktop. |
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:08 | Recall that in the Spoken Tutorial, 'Vector Operations', |
01:12 | matrix E was defined as E is equal to open square bracket 5 space 19 space 15 semicolon 8 space 22 space 36 close the square bracket 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 into bracket 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 into bracket 1 comma colon and press enter |
02:23 | 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:00 | E2 = E of colon comma 2 colon 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 $ (dollar ) 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 | Elast col= E into brackets colon comma dollar sign 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:19 | A = open square bracket 1 space 2 space minus 1 semicolon -2 space - 6 space 4 semicolon -1 space -3 space 3 close the square bracket and press enter |
04:50 | Let us calculate the determinant of A by the command det of 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 of A gives the inverse of A and spec of A gives the eigen values of matrix 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 square or A cube 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 the exercise number one given with the video. |
06:17 | 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 into bracket 3 comma 4 and press enter |
06:47 | A matrix of all ones can be created with “ones” command as follows |
06:53 | ones into bracket 2 comma 4 gives a matrix of all ones |
07:01 | It is easy to create an identity matrix using the “eye” command: |
07:07 | ' e y e' of 4 comma 4 gives a 4 by 4 identity matrix |
07:16 | 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 into bracket 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:07 | Recall that in the Spoken Tutorial,Vector Operations, we had defined the matrix P as follows. |
08:17 | P = open square bracket 1 space 2 space 3 semicolon 4 space 11 space 6 close the square bracket and press enter |
08:33 | 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:44 | 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:56 | P into bracket 2 comma colon is equal to P into bracket 2 comma colon minus 4 multiplied by P into bracket 1 comma colon and press enter |
09:28 | 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 the elements [5 5 -2] to P, the following command is used: |
09:48 | T = open square bracket P semicolon, open another square bracket write down the elements 5 5 -2 close both the square bracket and press enter |
10:14 | The semicolon after P states that 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:40 | 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 | and − 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 = open square bracket 1 space 2 space -1 semicolon -2 space -6 space 4 semicolon -1 space -3 space 3 close the square bracket and press enter |
11:46 | B can be defined as b is equal toSquare bracket 1 semicoln -2 semicolon 1 close the square bracket and press enter |
12:04 | The solution, x, can be obtained using x = inv of A multiplied by b |
12:19 | It is worth noting that it is a small letter 'i' in the command, 'inv'. |
12:26 | Alternatively, the same result can be achieved using a backslash operation in Scilab. |
12:33 | Lets do this in Scilab x is equal to A backslash b and press enter. |
12:44 | 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 multiplied by x minus 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:34 | 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:53 | 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:07 | Calculate the inverse of a matrix using the 'inv' command or by backslash |
14:14 | Calculate the derterminant of matrix using 'det' command. |
14:18 | Calculate eigen values of a matrix using 'spec' command. |
14:23 | Define a matrix having all the elements one, Null Matrix, 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:42 | 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 http://scilab.in |
14:58 | 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:14 | This is Anuradha Amrutkar from IIT Bombay signing off. |
15:18 | Thank you for joining. Goodbye. |
Contributors and Content Editors
Gaurav, Jyotisolanki, PoojaMoolya, Ranjana, Sandhya.np14, Sneha