Difference between revisions of "Scilab/C4/Linear-equations-Iterative-Methods/English-timed"
From Script | Spoken-Tutorial
PoojaMoolya (Talk | contribs) |
Sandhya.np14 (Talk | contribs) |
||
Line 399: | Line 399: | ||
| 06:43 | | 06:43 | ||
− | | Then we define the function '''Gauss Seidel''' with ''' | + | | Then we define the function '''Gauss Seidel''' with input arguments '''A comma b comma x zero comma max iterations''' and '''tolerance level''' and output argument '''solution'''. |
|- | |- |
Latest revision as of 23:54, 3 January 2018
Time | Narration |
00:01 | Dear Friends, Welcome to the Spoken Tutorial on Solving System of Linear Equations using Iterative Methods. |
00:10 | At the end of this tutorial, you will learn how to: |
00:14 | Solve system of linear equations using iterative methods |
00:18 | Develop Scilab code to solve linear equations. |
00:22 | To record this tutorial, I am using |
00:25 | Ubuntu 12.04 as the operating system |
00:28 | and Scilab 5.3.3 version. |
00:33 | Before practicing this tutorial, a learner should have basic knowledge of |
00:38 | Scilab, and solving linear equations. |
00:42 | For Scilab, please refer to the relevant tutorials available on the Spoken Tutorial website. |
00:50 | The first iterative method we will be studying is Jacobi method. |
00:56 | Given a system of linear equations, with n equations and n unknowns, |
01:02 | we rewrite the equations such that x of i k plus one is equal to b i minus summation of a i j x j k from j equal to one to n divided by a i i where i is from one to n. |
01:24 | We assume values for each x of i. |
01:27 | Then we substitute the values in the equations obtained in the previous step. |
01:34 | We continue the iteration until the solution converges. |
01:39 | Let us solve this example using Jacobi Method. |
01:44 | Let us look at the code for Jacobi Method. |
01:48 | We use format method to specify the format of the displayed answers on the Scilab console. |
01:56 | Here e denotes the answer should be in scientific notation. |
02:01 | And twenty specifies the number of digits to be displayed. |
02:06 | Then we use input function to get the values for |
02:10 | the matrices coefficient matrix, |
02:12 | right hand side matrix, |
02:14 | initial values matrix, |
02:17 | maximum number of iteration and |
02:19 | convergence tolerance. |
02:22 | Then we use size function to check if A matrix is a square matrix. |
02:29 | If it isn't, we use error function to display an error. |
02:34 | We then check if matrix A is diagonally dominant. |
02:40 | The first half calculates the sum of each row of the matrix. |
02:45 | Then it checks if twice the product of the diagonal element is greater than the sum of the elements of that row. |
02:54 | If it isn't, an error is displayed using error function. |
03:01 | Then we define the function Jacobi Iteration with input arguments |
03:07 | A, b , x zero, |
03:09 | maximum iteration and tolerance level. |
03:14 | Here x zero is the initial values matrix. |
03:19 | We check if the size of A matrix and initial values matrix are compatible with each other. |
03:28 | We calculate the value for x k p one and then check if the relative error is lesser than tolerance level. |
03:38 | If it is lesser than tolerance level, we break the iteration and the solution is returned. |
03:45 | Finally we end the function. |
03:48 | Let us save and execute the function. |
03:51 | Switch to Scilab console. |
03:54 | Let us enter the values at each prompt. |
03:57 | The coefficient matrix A is open square bracket two space one semi colon five space seven close square bracket |
04:08 | Press Enter. |
04:10 | Then we type open square bracket eleven semicolon thirteen close square bracket |
04:17 | Press Enter. |
04:20 | The initial values matrix is open square bracket one semi colon one close square bracket |
04:28 | Press Enter. |
04:30 | The maximum number of iterations is twenty five. |
04:34 | Press Enter. |
04:36 | Let the convergence tolerance level be zero point zero zero zero zero one |
04:44 | Press Enter. |
04:46 | We call the function by typing |
04:48 | Jacobi Iteration open parenthesis A comma b comma x zero comma M a x I t e r comma t o l close parenthesis |
05:04 | Press Enter. |
05:06 | The values for x one and x two are shown on the console. |
05:11 | The number of iterations are also shown. |
05:14 | Let us now study Gauss Seidel method. |
05:19 | 'Given a system of linear equations with n equations and n unknowns |
05:26 | we rewrite the equations for each unknown |
05:29 | by subtracting the other variables and their coefficients from the corresponding right hand side element. |
05:37 | Then we divide this by the coefficient a i i of the unknown variable' for that variable. |
05:45 | This is done for every given equation. |
05:49 | In Jacobi method, for the computation of x of i k plus one, every element of x of i k is used except x of i k plus one . |
06:03 | In Gauss Seidel method, we over write the value of x of i k with x of i k plus one. |
06:12 | Let us solve this example using Gauss Seidel Method. |
06:17 | Let us look at the code for Gauss Seidel Method. |
06:21 | The first line specifies the format of the displayed answer on the console using format function. |
06:29 | Then we use input function to get the values of |
06:32 | coefficient matrix, |
06:34 | right hand side matrix, |
06:36 | initial values of the variables matrix, |
06:38 | maximum number of iterations and |
06:40 | tolerance level. |
06:43 | Then we define the function Gauss Seidel with input arguments A comma b comma x zero comma max iterations and tolerance level and output argument solution. |
06:58 | We check if matrix A is square and the sizes of initial vector and matrix A are compatible using size and length function. |
07:10 | Then we start the iterations. |
07:13 | We equate the initial values vector x zero to x k. |
07:19 | We create a matrix of zeros with the same size of x k and call it x k p one. |
07:28 | We solve for each equation to get the value of the unknown variable for that equation using x k p one. |
07:38 | At each iteration, the value of x k p one gets updated. |
07:44 | Also, we check if relative error is lesser than specified tolerance level. |
07:50 | If it is, we break the iteration. |
07:54 | Then equate x k p one to the variable solution. |
07:59 | Finally, we end the function. |
08:02 | Let us save and execute the function. |
08:06 | Switch to Scilab console. |
08:09 | For the first prompt, we type matrix A. |
08:12 | Type open square bracket two space one semi colon five space seven close square bracket |
08:21 | Press Enter. For the next prompt, |
08:24 | type open square bracket eleven semi colon thirteen close square bracket |
08:31 | Press Enter. |
08:33 | We provide the values of initial value vector by typing |
08:38 | open square bracket one semicolon one close square bracket . |
08:43 | Press Enter. |
08:45 | Then we specify the maximum number of iterations to be twenty five. |
08:50 | Press Enter. |
08:52 | Let us define 'tolerance level to be zero point zero zero zero zero one. |
08:58 | Press Enter. |
09:01 | Finally we call the function by typing |
09:04 | G a u s s S e i d e l open parenthesis A comma b comma x zero comma M a x I t e r comma t o l close parenthesis |
09:24 | Press Enter. |
09:26 | The values of x one and x two are displayed. |
09:30 | The number of iterations to solve the same problem are lesser than Jacobi method. |
09:37 | Solve this problem on your own using Jacobi and Gauss Seidel methods. |
09:43 | In this tutorial, we have learnt to: |
09:47 | Develop Scilab code for solving system of linear equations. |
09:52 | Find the value of the unknown variables of a system of linear equations. |
09:58 | Watch the video available at the following link. |
10:01 | It summarizes the Spoken Tutorial project. |
10:04 | If you do not have good bandwidth, you can download and watch it. |
10:09 | The spoken tutorial project Team |
10:11 | conducts workshops using spoken tutorials, |
10:15 | gives certificates to those who pass an online test. |
10:18 | For more details, please write to contact@spoken-tutorial.org . |
10:25 | Spoken Tutorial Project is a part of the Talk to a Teacher project. |
10:30 | It is supported by the National Mission on Eduction through ICT, MHRD, Government of India. |
10:37 | More information on this mission is available at http://spoken-tutorial.org/NMEICT-Intro. |
10:49 | This is Ashwini Patil. signing off. |
10:51 | Thank you for joining. |