Scilab/C4/Linear-equations-Gaussian-Methods/English-timed
From Script | Spoken-Tutorial
Revision as of 17:28, 27 February 2015 by Sandhya.np14 (Talk | contribs)
Time | Narration |
00:01 | Dear Friends, |
00:02 | Welcome to the spoken tutorial on Solving System of Linear Equations using Gauss Elimination and Gauss-Jordan Methods. |
00:12. | At the end of this tutorial, you will learn how to: |
00:15 | Solve system of linear equations using Scilab |
00:20 | Develop Scilab code to solve linear equations. |
00:25 | To record this tutorial, I am using |
00:27 | Ubuntu 12.04 as the operating system |
00:31 | with Scilab 5.3.3 version. |
00:36 | To practice this tutorial, a learner should have basic knowledge of Scilab |
00:40 | and should know how to solve Linear Equations. |
00:45 | To learn Scilab, please refer to the relevant tutorials available on the Spoken Tutorial website. |
00:52 | A system of linear equations is a |
00:55 | finite collection of linear equations of the same set of variables. |
01:00 | Let us study Gauss elimination method. |
01:04 | Given a system of equations |
01:06 | A x equal to b |
01:08 | with m equations and |
01:10 | n unknowns. |
01:12 | We write the coefficients of the variables a one to a n |
01:16 | along with the constants b one to b n of the system of equations |
01:22 | in one matrix called the augmented matrix. |
01:27 | How do we convert the augmented matrix to an upper triangular form matrix? |
01:33 | We do so by performing row wise manipulation of the matrix. |
01:40 | Let us solve this system of equations using Gaussian elimination method. |
01:45 | Before we solve the system, let us go through the code for Gaussian elimination method. |
01:52 | The first line of the code is format e comma twenty. |
01:58 | This defines how many digits should be displayed in the answer. |
02:04 | The letter 'e' within single quotes denotes that the answer should be displayed in scientific notation. |
02:12 | The number twenty is the number of digits that should be displayed. |
02:17 | The command funcprot is used to let Scilab know what to do when variables are redefined. |
02:26 | The argument zero specifies that Scilab need not do anything if the variables are redefined. |
02:33 | Other arguments are used to issue warnings or errors if the variables are redefined. |
02:40 | Next we use the input function. |
02:43 | It will display a message to the user and get the values of A and B matrices. |
02:51 | The message should be placed within double quotes. |
02:55 | The matrices that the user enters, will be stored in the variables A and b. |
03:02 | Here A is the coefficient matrix and b is the right-hand-side matrix or the constants matrix. |
03:11 | Then we define the function naive gaussian elimination. |
03:15 | And we state that A and b are the arguments of the function naive gaussian elimination. |
03:22 | We store the output in variable x. |
03:27 | Then we find the size of matrices A and b using the size command. |
03:34 | Since they are two dimensional matrices, we use n and n one to store the size of matrix A. |
03:42 | Similarly we can use m one and p for matrix b. |
03:48 | Then we have to determine if the matrices are compatible with each other and |
03:53 | if A is a square matrix. |
03:57 | If n and n one are not equal, then we display a message that Matrix A must be square. |
04:05 | If n and m one are not equal, we display a message |
04:10 | incompatible dimension of A and b. |
04:15 | If the matrices are compatible, we place matrices A and b in one matrix, C. |
04:23 | This matrix C is called augmented matrix. |
04:28 | The next block of code performs forward elimination. |
04:32 | This code converts the augmented matrix to upper triangular matrix form. |
04:39 | Finally, we perform back substitution. |
04:42 | Once the upper triangular matrix is obtained, we take the last row and find the value of the variable in that row. |
04:52 | Then once one variable is solved, we take this variable to solve the other variables. |
04:59 | Thus the system of linear equations is solved. |
05:03 | Let us save and execute the file. |
05:06 | Switch to Scilab console to solve the example. |
05:10 | On the console, we have a prompt to enter the value of the coefficient matrix. |
05:17 | So we enter the values of matrix A. |
05:20 | Type square bracket three point four one space one point two three space minus one point zero nine semi colon |
05:33 | two point seven one space two point one four space one point two nine semi colon |
05:41 | one point eight nine space minus one point nine one space minus one point eight nine close square bracket. |
05:53 | Press Enter. |
05:54 | The next prompt is for matrix b. |
05:57 | So we type |
05:58 | open square bracket four point seven two semi colon three point one semi colon two point nine one close square bracket. |
06:10 | Press Enter. |
06:13 | Then we call the function by typing |
06:16 | naive gaussian elimination open parenthesis A comma b close parenthesis |
06:24 | Press Enter. |
06:26 | The solution to the system of linear equations is shown on Scilab console. |
06:32 | Next we shall study the Gauss- Jordan method. |
06:36 | In Gauss – Jordan Method, |
06:38 | the first step is to form the augmented matrix. |
06:42 | To do this place the coefficient matrix A and the right hand side matrix b together in one matrix. |
06:50 | Then we perform row operations to convert matrix A to diagonal form. |
06:56 | In diagonal form, only the elements a i i are non-zero. Rest of the elements are zero. |
07:05 | Then we divide the diagonal element and corresponding element of right hand side element, by the diagonal element. |
07:14 | We do this to get diagonal element equal to one. |
07:19 | The resulting value of the elements of each row of the right hand side matrix gives the value of each variable. |
07:27 | Let us solve this example using Gauss-Jordan Method. |
07:33 | Let us look at the code first. |
07:36 | The first line of the code uses format function to specify the format of the displayed answers. |
07:44 | The parameter e specifies the answer should be in scientific notation. |
07:49 | Twenty (20) denotes that only twenty digits should be displayed. |
07:55 | Then we get the A and b matrix using the input function. |
08:00 | We define the function Gauss Jordan Elimination with input arguments A and b and output argument x. |
08:11 | We get the size of matrix A and store it in m and n. |
08:17 | Similarly, we get the size of matrix b and store it in r and s. |
08:23 | If the sizes of A and b are not compatible, we display an error on the console using error function. |
08:33 | Then we perform row operations to get diagonal form of the matrix. |
08:38 | Here pivot refers to the first non-zero element of a column. |
08:45 | Then we create a matrix of zeros called x with m rows and s columns. |
08:52 | Once we have the diagonal form, |
08:54 | we divide the right hand side part of augmented matrix by the corresponding diagonal element to get the value of each variable. |
09:04 | We store the value of each variable in x. |
09:08 | Then we return the value of x. |
09:11 | Finally, we end the function. |
09:13 | Now let us save and execute the function. |
09:18 | The prompt requires us to enter the value of matrix A. |
09:22 | So we type |
09:23 | open square bracket zero point seven comma one seven two five semi colon |
09:31 | zero point four three five two comma minus five point four three three close square bracket. |
09:41 | Press Enter. |
09:43 | The next prompt is for vector b. |
09:45 | So we type open square bracket one seven three nine semi colon |
09:51 | three point two seven one close square bracket. |
09:55 | Press Enter. |
09:58 | Then we call the function by typing |
10:01 | Gauss Jordan Elimination open parenthesis A comma b close parenthesis |
10:08 | Press Enter |
10:10 | The values of x one and x two are shown on the console. |
10:15 | Let us summarize this tutorial. |
10:18 | In this tutorial, we have learnt to: |
10:21 | Develop Scilab code for solving system of linear equations |
10:25 | Find the value of the unknown variables of a system of linear equations |
10:32 | Watch the video available at the link shown below. |
10:35 | It summarizes the Spoken Tutorial project. |
10:38 | If you do not have good bandwidth, you can download and watch it. |
10:43 | The spoken tutorial project Team: |
10:45 | Conducts workshops using spoken tutorials. |
10:48 | Gives certificates to those who pass an online test. |
10:52 | For more details, please write to conatct@spoken-tutorial.org. |
10:59 | Spoken Tutorial Project is a part of the Talk to a Teacher project. |
11:03 | It is supported by the National Mission on Eduction through ICT, MHRD, Government of India. |
11:10 | More information on this mission is available at http://spoken-tutorial.org/NMEICT-Intro. |
11:21 | This is Ashwini Patil, signing off. |
11:23 | Thank you for joining. |