Difference between revisions of "Scilab/C4/Linear-equations-Gaussian-Methods/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with ''''Title of script''': Solving System of Linear Equations using Gauss Elimination and Gauss-Jordan Methods '''Author: Shamika''' '''Keywords: System of linear equations, Gaussi…')
 
 
(6 intermediate revisions by 2 users not shown)
Line 6: Line 6:
  
  
{| style="border-spacing:0;"
+
{|border=1
 
! <center>Visual Cue</center>
 
! <center>Visual Cue</center>
 
! <center>Narration</center>
 
! <center>Narration</center>
Line 22: Line 22:
 
* Solve system of linear equations using '''Scilab'''
 
* Solve system of linear equations using '''Scilab'''
 
* Develop '''Scilab''' code to solve linear equations  
 
* Develop '''Scilab''' code to solve linear equations  
 
 
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 3-System Requirement slide
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 3-System Requirement slide
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| To record this tutorial, I am using '''Ubuntu 12.04''' as the operating system
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| To record this tutorial, I am using  
  
with '''Scilab 5.3.3''' version  
+
*'''Ubuntu 12.04''' as the operating system
 +
*and '''Scilab 5.3.3''' version  
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 4- Prerequisites slide
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 4- Prerequisites slide
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * To practise this tutorial, a learner should have basic knowledge of '''Scilab '''and should know how to solve''' Linear Equations.'''
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| To practise this tutorial, a learner  
 +
*should have basic knowledge of '''Scilab '''
 +
*and should know how to solve''' Linear Equations.'''
  
* To learn '''Scilab''', please refer to the relevant tutorials available on the '''Spoken Tutorial '''website.  
+
 
 +
To learn '''Scilab''', please refer to the relevant tutorials available on the '''Spoken Tutorial '''website.  
  
  
Line 45: Line 47:
 
* '''linear equations'''
 
* '''linear equations'''
 
* of the same set of '''variables'''
 
* of the same set of '''variables'''
 
 
  
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 6- System of Linear Equations
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 7- Gaussian Elimination Method
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| A system of''' linear equations '''can have one of the following conclusions
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us study '''Gauss elimination method'''
  
* No solution
+
Given a system of equations
* Unique solution
+
* Infinitely many solutions
+
 
+
 
+
 
+
|-
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 7- Gaussian Elimination Method
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Given a system of equations
+
  
* '''Ax=b''' (a x equal to b)
+
* '''A x equal to b'''
 
* with '''m '''equations and''' '''
 
* with '''m '''equations and''' '''
 
* '''n '''unknowns
 
* '''n '''unknowns
 
 
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 8- Gaussian Elimination Method
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 8- Gaussian Elimination Method
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * We write the coefficients of the '''variables''' '''a one''' to''' a n'''  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|  
* along with the '''constants b one''' to''' b n''' of the system of the equations  
+
* We write the coefficients of the '''variables''' '''a one''' to''' a n'''  
 +
* along with the '''constants b one''' to''' b m''' of the system of equations  
 
* in one '''matrix''' called the '''augmented matrix'''
 
* in one '''matrix''' called the '''augmented matrix'''
 
 
  
 
|-
 
|-
Line 81: Line 70:
  
  
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * How do we convert the '''augmented matrix '''to an '''upper triangular form''' '''matrix?'''
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| How do we convert the '''augmented matrix '''to an '''upper triangular form matrix?'''
* We do so''' '''by performing row wise manipulation of the '''matrix'''.
+
  
  
 +
We do so by performing row wise manipulation of the '''matrix'''.
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 10- Example
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 10- Example
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Let us solve this system of equations using '''Gaussian elimination method'''
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us solve this system of equations using '''Gaussian elimination method'''
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Switch to Scilab and open naivegaussianelimination.sci
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Switch to Scilab and open naivegaussianelimination.sci
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Before we solve the system, let us go through the code for '''Gaussian elimination method'''.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Before we solve the system, let us go through the code for '''Gaussian elimination method'''.
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight '''format e comma twenty'''
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight '''format e comma twenty'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * The first line of the code is '''format e comma twenty.'''
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The first line of the code is '''format e comma twenty.'''
* This''' '''defines how many digits should be displayed in the answer.
+
  
  
 +
This defines how many digits should be displayed in the answer.
  
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Point to '''e'''
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Point to '''e '''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * The letter '''e''' within single quotes denotes that the answer should be displayed in scientific notation  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The letter ''''e'''' within single quotes denotes that the answer should be displayed in '''scientific notation '''
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Point to '''twenty'''
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Point to '''twenty'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * The number '''20''' is the number of digits that should be displayed.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The number '''twenty''' is the number of digits that should be displayed.  
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight '''funcprot'''
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight '''funcprot'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * The command '''funcprot''' is used to let '''Scilab '''know what to do when variables are redefined.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The command '''funcprot''' is used to let '''Scilab '''know what to do when variables are redefined.
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Point to '''zero'''
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Point to '''zero'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * The argument '''zero''' specifies that '''Scilab''' need not do anything if the variables are redefined.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The argument '''zero''' specifies that '''Scilab''' need not do anything if the variables are redefined.
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| No visual clue. This is extra information that is being offered to the listener.  
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| No visual clue. This is extra information that is being offered to the listener.  
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Other arguments are used to issue warnings or errors if the variables are redefined.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Other arguments are used to issue warnings or errors if the variables are redefined.
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight '''input'''
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight '''input'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Next we use the '''input''' function.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Next we use the '''input''' function.
 
+
 
+
  
 
|-
 
|-
Line 145: Line 118:
  
  
Poin to '''“ “'''
+
Point to '''“ “'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * It will display a message to the user and get the values of '''A''' and '''B''' matrices.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| It will display a message to the user and get the values of '''A''' and '''B''' matrices.  
* The message should be placed within '''double quotes'''.  
+
  
  
 +
The message should be placed within '''double quotes'''.
  
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Extra information
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"|  
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * The matrices that the user inputs, will be stored in the variables '''A''' and '''B'''.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The matrices that the user enters, will be stored in the variables '''A''' and '''b'''.  
 
+
 
+
  
 
|-
 
|-
Line 161: Line 132:
  
 
Highlight '''B'''
 
Highlight '''B'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Here '''A''' is the coefficient matrix and '''B''' is the right-hand-side matrix or the '''constants''' matrix.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Here '''A''' is the '''coefficient matrix''' and '''b''' is the right-hand-side matrix or the '''constants matrix'''.
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight '''naivegaussianelimination'''
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight '''naivegaussianelimination'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Then we define the function '''naivegaussianelimination.'''
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Then we define the function '''naive gaussian elimination.'''
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight '''A'''
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight '''A'''
  
Highlight '''B'''
+
Highlight '''b'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * And we state that '''A''' and '''B''' are the arguments of the function '''naivegaussianelimination'''.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| And we state that '''A''' and '''b''' are the '''arguments''' of the function '''naive gaussian elimination'''.  
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight '''x'''
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight '''x'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * We store the output in variable '''x'''.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We store the output in variable '''x'''.
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight '''size'''
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight '''size'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Then we find the size of matrices '''A''' and '''B''' using the '''size''' command.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Then we find the size of matrices '''A''' and '''b''' using the '''size''' command.
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight''' n and n one'''
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight''' n and n one'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Since they are 2-dimensional matrices, we use '''n''' and '''n one''' to store the size of matrix '''A.'''
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Since they are two dimensional matrices, we use '''n''' and '''n one''' to store the size of matrix '''A.'''
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight '''m one '''and '''p'''
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight '''m one '''and '''p'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Similarly we can use '''m one '''and '''p''' for matrix '''b'''.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Similarly we can use '''m one '''and '''p''' for matrix '''b'''.  
 
+
 
+
  
 
|-
 
|-
Line 209: Line 166:
  
 
'''error('gaussianelimination - Matrix A must be square');'''
 
'''error('gaussianelimination - Matrix A must be square');'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Then we have to determine if the matrices are compatible with each other and if '''A''' is a '''square matrix'''.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Then we have to determine  
* If '''n''' and '''n one''' are not equal , then we display a message that '''Matrix A''' must be square.  
+
*if the matrices are compatible with each other and  
 +
*if '''A''' is a '''square matrix'''.  
  
  
 +
If '''n''' and '''n one''' are not equal, then we display a message '''Matrix A must be square'''.
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight  
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight  
  
'''elseif n ~= m1 error('gaussianelimination - incompatible dimension of A & b');'''
+
'''elseif n ~= m1 '''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * If '''n''' and '''m''' one are not equal, we display a message incompatible dimension of '''A''' and '''b.'''
+
 
+
  
 +
'''error('gaussianelimination - incompatible dimension of A & b');'''
 +
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| If '''n''' and '''m''' one are not equal, we display a message
 +
'''incompatible dimension of A and b'''.
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight  
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight  
  
'''<nowiki>C=[A b]</nowiki>'''
+
'''<nowiki>C=[A b];</nowiki>'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * If the matrices are compatible, we place matrices '''A''' and '''b''' in one matrix '''C'''.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| If the matrices are compatible, we place matrices '''A''' and '''b''' in one matrix, '''C'''.  
* This matrix '''C''' is called '''augmented matrix'''.
+
  
  
 +
This matrix '''C''' is called '''augmented matrix'''.
  
 
|-
 
|-
Line 253: Line 213:
  
 
'''end'''
 
'''end'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * The next block of code performs '''forward elimination'''.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The next block of code performs '''forward elimination'''.  
* This code converts the '''augmented matrix''' to '''upper triangular matrix''' form.  
+
 
 +
This code converts the '''augmented matrix''' to '''upper triangular matrix''' form.  
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
  
  
Line 276: Line 246:
  
 
'''end'''
 
'''end'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Finally we perform '''back substitution'''.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|  
 +
* Finally, we perform '''back substitution'''.  
 
* Once the '''upper triangular matrix''' is obtained, we take the last row and find the value of the variable in that row.  
 
* Once the '''upper triangular matrix''' is obtained, we take the last row and find the value of the variable in that row.  
 
* Then once one variable is solved, we take this variable to solve the other variables.  
 
* Then once one variable is solved, we take this variable to solve the other variables.  
Line 285: Line 256:
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Click on Execute and select Save and Execute
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Click on Execute and select Save and Execute
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Let us save and execute the file.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us save and execute the file.  
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Show Scilab Console
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Show Scilab Console
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Switch to Scilab console to solve the example.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Switch to '''Scilab console''' to solve the example.  
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Show Scilab Console
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Show Scilab Console
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * On the console, we have a prompt to enter the value of the coefficient matrix.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| On the '''console''', we have a prompt to enter the value of the '''coefficient matrix'''.  
* So we enter the values of '''matrix A'''.
+
  
  
 +
So we enter the values of '''matrix A'''.
  
 
|-
 
|-
Line 306: Line 273:
  
 
'''<nowiki>[3.41 1.23 -1.09;2.71 2.14 1.29;1.89 -1.91 -1.89]</nowiki>'''
 
'''<nowiki>[3.41 1.23 -1.09;2.71 2.14 1.29;1.89 -1.91 -1.89]</nowiki>'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Type '''square bracket three point four one space one point two three space minus one point zero nine semi colon two point seven one space two point one four space one point two nine semi colon one point eight nine space minus one point nine one space minus one point eight nine close square bracket.'''
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Type '''square bracket three point four one space one point two three space minus one point zero nine semi colon '''
* '''Press enter'''
+
  
 +
'''two point seven one space two point one four space one point two nine semi colon '''
  
 +
'''one point eight nine space minus one point nine one space minus one point eight nine close square bracket.'''
 +
 +
Press '''Enter'''
  
 
|-
 
|-
Line 315: Line 285:
  
 
'''<nowiki>[4.72;3.1;2.92]</nowiki>'''
 
'''<nowiki>[4.72;3.1;2.92]</nowiki>'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * The next prompt is for '''matrix b'''.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The next prompt is for '''matrix b'''.
* So we type
+
 
* '''open square bracket four point seven two semi colon three point one semi colon two point nine two close square bracket. '''
+
* '''Press enter'''
+
  
 +
So we type
  
 +
'''open square bracket four point seven two semi colon three point one semi colon two point nine one close square bracket.'''
 +
 +
Press '''Enter'''
  
 
|-
 
|-
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| '''Type'''
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Type  
  
 
'''naivegaussianelimination(A,b)'''
 
'''naivegaussianelimination(A,b)'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Then we call the function by typing  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Then we call the function by typing  
* '''naive gaussian elimination open paranthesis A comma b close paranthesis '''
+
* '''Press enter'''
+
  
 +
'''naive gaussian elimination open paranthesis A comma b close paranthesis '''
  
 +
 +
Press '''Enter'''
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Show answer on Scilab console
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Show answer on Scilab console
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * The solution to the system of linear equations is shown on Scilab console.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The solution to the system of linear equations is shown on '''Scilab console'''.  
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"|  
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"|  
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Next we shall study the '''Gauss- Jordan''' '''method'''.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Next we shall study the '''Gauss- Jordan''' '''method'''.  
 
+
 
+
  
 
|-
 
|-
Line 350: Line 319:
 
* The first step is to form the '''augmented matrix. '''
 
* The first step is to form the '''augmented matrix. '''
 
* To do this place the coefficient '''matrix A''' and the right hand side '''matrix b''' together in one '''matrix'''.
 
* To do this place the coefficient '''matrix A''' and the right hand side '''matrix b''' together in one '''matrix'''.
* Then we perform '''row operations t'''o convert '''matrix A '''to diagonal form.  
+
* Then we perform '''row operations''' to convert '''matrix A '''to diagonal form.  
 
* In diagonal form, only the elements '''a i i '''are non-zero. Rest of the elements are zero.
 
* In diagonal form, only the elements '''a i i '''are non-zero. Rest of the elements are zero.
 
 
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 12- Gauss-Jordan Method
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 12- Gauss-Jordan Method
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Then we divide the diagonal element and corresponding element of right hand side element, by the diagonal element.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Then we divide the diagonal element and corresponding element of right hand side element, by the diagonal element.
* We do this to get diagonal element equal to one.
+
* The resulting value of the elements of each row of the right hand side matrix gives the value of each variable.
+
  
  
 +
We do this to get '''diagonal element''' equal to one.
 +
 +
 +
The resulting value of the elements of each row of the right hand side matrix gives the value of each variable.
  
 
|-
 
|-
Line 368: Line 337:
  
  
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Let us solve this example using '''Gauss- Jordan Method'''.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us solve this example using '''Gauss- Jordan Method'''.  
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Switch to Scilab console and open GaussJordan Elimination.sci
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Switch to Scilab console and open GaussJordan Elimination.sci
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Let us look at the code first.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us look at the code first.  
 
+
 
+
  
 
|-
 
|-
Line 382: Line 347:
  
 
'''format'''
 
'''format'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * The first line of the code uses '''format function''' to specify the format of the displayed answers.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The first line of the code uses '''format function''' to specify the format of the displayed answers.  
 
+
 
+
  
 
|-
 
|-
Line 390: Line 353:
  
 
''''e''''
 
''''e''''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * The parameter '''e''' specifies the answer should be in '''scientific notation'''.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The parameter '''e''' specifies the answer should be in '''scientific notation'''.
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight '''20'''
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight '''20'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * 20 denotes that only 20 digits should be displayed.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| '''Twenty (20)''' denotes that only '''twenty digits''' should be displayed.
 
+
 
+
  
 
|-
 
|-
Line 406: Line 365:
  
 
'''b=input("Enter the right-hand side matrix : ")'''
 
'''b=input("Enter the right-hand side matrix : ")'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Then we get the '''A''' and '''b matrix''' using the '''input function'''.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Then we get the '''A''' and '''b matrix''' using the '''input function'''.  
 
+
 
+
  
 
|-
 
|-
Line 414: Line 371:
  
 
'''<nowiki>function [x] = GaussJordanElimination( A, b )</nowiki>'''
 
'''<nowiki>function [x] = GaussJordanElimination( A, b )</nowiki>'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * We define the function '''Gauss Jordan Elimination''' with input arguments '''A '''and''' b''' and output argument''' x.'''
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We define the function '''Gauss Jordan Elimination''' with input arguments '''A '''and''' b''' and output argument''' x.'''
 
+
 
+
  
 
|-
 
|-
Line 422: Line 377:
  
 
'''<nowiki>[m, n] = size( A )</nowiki>'''
 
'''<nowiki>[m, n] = size( A )</nowiki>'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * We get the size of '''matrix A''' and store it in '''m''' and '''n'''
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We get the size of '''matrix A''' and store it in '''m''' and '''n'''
 
+
 
+
  
 
|-
 
|-
Line 430: Line 383:
  
 
'''<nowiki>[r, s] = size( b )</nowiki>'''
 
'''<nowiki>[r, s] = size( b )</nowiki>'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Similarly we get the size of '''matrix b '''and store it in '''r''' and '''s'''
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Similarly, we get the size of '''matrix b '''and store it in '''r''' and '''s'''
 
+
 
+
  
 
|-
 
|-
Line 442: Line 393:
  
 
'''end'''
 
'''end'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * If the sizes of '''A '''and '''b''' are not compatible, we display an error on the console using '''error function'''.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| If the sizes of '''A '''and '''b''' are not compatible, we display an error on the '''console''' using '''error function'''.  
 
+
 
+
  
 
|-
 
|-
Line 471: Line 420:
  
 
'''end'''
 
'''end'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Then we perform '''row operations''' to get diagonal form of the '''matrix'''.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Then we perform '''row operations''' to get diagonal form of the '''matrix'''.
* Here '''pivot''' refers to the first non-zero element of a column.  
+
  
  
 +
Here '''pivot''' refers to the first non-zero element of a '''column'''.
  
 
|-
 
|-
Line 480: Line 429:
  
 
'''x = zeros( m, s )'''
 
'''x = zeros( m, s )'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Then we create a '''matrix''' of zeros called '''x''' with '''m''' rows and '''s''' columns.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Then we create a '''matrix''' of zeros called '''x''' with '''m''' rows and '''s columns'''.
 
+
 
+
  
 
|-
 
|-
Line 499: Line 446:
  
 
* we divide the right hand side part of '''augmented matrix'''  
 
* we divide the right hand side part of '''augmented matrix'''  
* by the corresponding diagonal element  
+
* by the corresponding '''diagonal element '''
 
* to get the value of each variable.
 
* to get the value of each variable.
 
  
  
Line 508: Line 454:
  
 
'''x(i, j) = C(i, m+j) / C(i, i) '''
 
'''x(i, j) = C(i, m+j) / C(i, i) '''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * We store the value of each variable in '''x.'''
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We store the value of each variable in '''x.'''
 
+
 
+
  
 
|-
 
|-
Line 516: Line 460:
  
 
'''return x'''
 
'''return x'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Then we return the value of '''x.'''  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Then we return the value of '''x.'''  
 
+
  
  
Line 524: Line 467:
  
 
'''endfunction'''
 
'''endfunction'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Finally we end the function.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Finally, we '''end''' the function.
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Click on Execute and select Save and Execute
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Click on Execute and select Save and Execute
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Now let us save and execute the function.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Now let us save and execute the function.
 
+
 
+
  
 
|-
 
|-
Line 541: Line 480:
  
  
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * The prompt requires us to enter the value of '''matrix A'''.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The prompt requires us to enter the value of '''matrix A'''.  
* So we type
+
* '''open square bracket zero point seven comma one seven two five semi colon zero point four three five two comma minus five point four three three close square bracket.'''
+
* '''Press enter'''
+
  
  
 +
So we type
 +
 +
'''open square bracket zero point seven comma one seven two five semi colon '''
 +
 +
'''zero point four three five two comma minus five point four three three close square bracket.'''
 +
 +
Press '''Enter'''
  
 
|-
 
|-
Line 552: Line 495:
  
 
'''<nowiki>[1739;3.271]</nowiki>'''
 
'''<nowiki>[1739;3.271]</nowiki>'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * The next prompt is for '''vector b'''.  
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The next prompt is for '''vector b'''.  
* So we type
+
* '''open squre bracket one seven three nine semi colon three point two seven one close square bracket'''
+
* '''Press enter'''
+
  
  
 +
So we type
 +
 +
'''open squre bracket one seven three nine semi colon '''
 +
 +
'''three point two seven one close square bracket'''
 +
 +
Press '''Enter'''
  
 
|-
 
|-
Line 563: Line 510:
  
 
'''GaussJordanElimination(A,b)'''
 
'''GaussJordanElimination(A,b)'''
 +
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Then we call the function by typing
  
 +
'''Gauss Jordan Elimination open paranthesis A comma b close paranthesis'''
  
 
+
Press '''Enter'''
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Then we call the function by typing
+
* '''Gauss Jordan Elimination open paranthesis A comma b close paranthesis'''
+
* '''press enter'''
+
* Please note that the letters '''G J E '''are in capital.
+
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Show answers on Scilab console
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Show answers on Scilab console
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * The values of '''x one''' and '''x two''' are '''twenty''' and '''one''' respectively.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The values of '''x one''' and '''x two''' are shown on the '''console'''.
 
+
 
+
  
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 14- Summary
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 14- Summary
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| <nowiki><Pause></nowiki>
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us summarize this tutorial.
 
+
Let us summarize.
+
  
 
In this tutorial, we have learnt to:  
 
In this tutorial, we have learnt to:  
  
* Develop Scilab code for solving system of '''linear equations'''  
+
* Develop '''Scilab''' code for solving system of '''linear equations'''  
* Find the value of the unknown variables of a system of '''linear '''
+
* Find the value of the unknown variables of a system of '''linear equations '''
 
+
'''equations '''
+
  
 
|-
 
|-
Line 604: Line 541:
  
  
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * About the Spoken Tutorial Project<br/>
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Watch the video available at the following link
 
+
* It summarises the Spoken Tutorial project  
* Watch the video available at [http://spoken-tutorial.org/ http://spoken-tutorial.org]/What_is_a_Spoken_Tutorial <br/>
+
 
+
* It summarises the Spoken Tutorial project<br/>
+
 
+
 
* If you do not have good bandwidth, you can download and watch it  
 
* If you do not have good bandwidth, you can download and watch it  
 +
*
  
  
Line 662: Line 596:
 
|-
 
|-
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"|  
 
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"|  
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| This is Bella Tony from the FOSSEE project, IIT Bombay signing off. Thanks for joining.
+
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| This is mandatory. This is Ashwini Patil signing off. Thanks for joining.
  
 
|}
 
|}

Latest revision as of 16:37, 5 February 2016

Title of script: Solving System of Linear Equations using Gauss Elimination and Gauss-Jordan Methods

Author: Shamika

Keywords: System of linear equations, Gaussian Methods


Visual Cue
Narration
Slide 1 Dear Friends,

Welcome to the Spoken Tutorial on “Solving System of Linear Equations using Gauss Elimination and Gauss-Jordan Methods

Slide 2 -Learning Objective Slide At the end of this tutorial, you will learn how to:
  • Solve system of linear equations using Scilab
  • Develop Scilab code to solve linear equations
Slide 3-System Requirement slide To record this tutorial, I am using
  • Ubuntu 12.04 as the operating system
  • and Scilab 5.3.3 version
Slide 4- Prerequisites slide To practise this tutorial, a learner
  • should have basic knowledge of Scilab
  • and should know how to solve Linear Equations.


To learn Scilab, please refer to the relevant tutorials available on the Spoken Tutorial website.


Slide 5- System of Linear Equations A system of linear equations is a
  • Finite collection of
  • linear equations
  • of the same set of variables
Slide 7- Gaussian Elimination Method Let us study Gauss elimination method

Given a system of equations

  • A x equal to b
  • with m equations and
  • n unknowns
Slide 8- Gaussian Elimination Method
  • We write the coefficients of the variables a one to a n
  • along with the constants b one to b m of the system of equations
  • in one matrix called the augmented matrix
Slide 9- Gaussian Elimination Method


How do we convert the augmented matrix to an upper triangular form matrix?


We do so by performing row wise manipulation of the matrix.

Slide 10- Example Let us solve this system of equations using Gaussian elimination method
Switch to Scilab and open naivegaussianelimination.sci Before we solve the system, let us go through the code for Gaussian elimination method.
Highlight format e comma twenty The first line of the code is format e comma twenty.


This defines how many digits should be displayed in the answer.

Point to e The letter 'e' within single quotes denotes that the answer should be displayed in scientific notation
Point to twenty The number twenty is the number of digits that should be displayed.
Highlight funcprot The command funcprot is used to let Scilab know what to do when variables are redefined.
Point to zero The argument zero specifies that Scilab need not do anything if the variables are redefined.
No visual clue. This is extra information that is being offered to the listener. Other arguments are used to issue warnings or errors if the variables are redefined.
Highlight input Next we use the input function.
Highlight input


Point to “ “

It will display a message to the user and get the values of A and B matrices.


The message should be placed within double quotes.

The matrices that the user enters, will be stored in the variables A and b.
Highlight A

Highlight B

Here A is the coefficient matrix and b is the right-hand-side matrix or the constants matrix.
Highlight naivegaussianelimination Then we define the function naive gaussian elimination.
Highlight A

Highlight b

And we state that A and b are the arguments of the function naive gaussian elimination.
Highlight x We store the output in variable x.
Highlight size Then we find the size of matrices A and b using the size command.
Highlight n and n one Since they are two dimensional matrices, we use n and n one to store the size of matrix A.
Highlight m one and p Similarly we can use m one and p for matrix b.
Highlight

if n ~= n1

error('gaussianelimination - Matrix A must be square');

Then we have to determine
  • if the matrices are compatible with each other and
  • if A is a square matrix.


If n and n one are not equal, then we display a message Matrix A must be square.

Highlight

elseif n ~= m1

error('gaussianelimination - incompatible dimension of A & b');

If n and m one are not equal, we display a message

incompatible dimension of A and b.

Highlight

C=[A b];

If the matrices are compatible, we place matrices A and b in one matrix, C.


This matrix C is called augmented matrix.

Highlight

n=size(A,1);

for k=1:n-1

for i=k+1:n

factor=A(i,k)/A(k,k);

for j=k+1:n

A(i,j)=A(i,j)-factor*A(k,j);

end

b(i)=b(i)-factor*b(k);

end

end

The next block of code performs forward elimination.

This code converts the augmented matrix to upper triangular matrix form.







Highlight

x(n)=b(n)/A(n,n);

for i=n-1:-1:1

sum=0;

for j=i+1:n

sum=sum+A(i,j)*x(j);

end

x(i)=(b(i)-sum)/A(i,i);

end

  • Finally, we perform back substitution.
  • Once the upper triangular matrix is obtained, we take the last row and find the value of the variable in that row.
  • Then once one variable is solved, we take this variable to solve the other variables.
  • Thus the system of linear equations is solved.


Click on Execute and select Save and Execute Let us save and execute the file.
Show Scilab Console Switch to Scilab console to solve the example.
Show Scilab Console On the console, we have a prompt to enter the value of the coefficient matrix.


So we enter the values of matrix A.

Type

[3.41 1.23 -1.09;2.71 2.14 1.29;1.89 -1.91 -1.89]

Type square bracket three point four one space one point two three space minus one point zero nine semi colon

two point seven one space two point one four space one point two nine semi colon

one point eight nine space minus one point nine one space minus one point eight nine close square bracket.

Press Enter

Type

[4.72;3.1;2.92]

The next prompt is for matrix b.


So we type

open square bracket four point seven two semi colon three point one semi colon two point nine one close square bracket.

Press Enter

Type

naivegaussianelimination(A,b)

Then we call the function by typing

naive gaussian elimination open paranthesis A comma b close paranthesis


Press Enter

Show answer on Scilab console The solution to the system of linear equations is shown on Scilab console.
Next we shall study the Gauss- Jordan method.
Slide 11 – Gauss- Jordan Method In Gauss – Jordan Method
  • The first step is to form the augmented matrix.
  • To do this place the coefficient matrix A and the right hand side matrix b together in one matrix.
  • Then we perform row operations to convert matrix A to diagonal form.
  • In diagonal form, only the elements a i i are non-zero. Rest of the elements are zero.
Slide 12- Gauss-Jordan Method Then we divide the diagonal element and corresponding element of right hand side element, by the diagonal element.


We do this to get diagonal element equal to one.


The resulting value of the elements of each row of the right hand side matrix gives the value of each variable.

Slide 13- Example


Let us solve this example using Gauss- Jordan Method.
Switch to Scilab console and open GaussJordan Elimination.sci Let us look at the code first.
Highlight

format

The first line of the code uses format function to specify the format of the displayed answers.
Highlight

'e'

The parameter e specifies the answer should be in scientific notation.
Highlight 20 Twenty (20) denotes that only twenty digits should be displayed.
Highlight

A=input("Enter the coeffiecient matrix : ")

b=input("Enter the right-hand side matrix : ")

Then we get the A and b matrix using the input function.
Highlight

function [x] = GaussJordanElimination( A, b )

We define the function Gauss Jordan Elimination with input arguments A and b and output argument x.
Highlight

[m, n] = size( A )

We get the size of matrix A and store it in m and n
Highlight

[r, s] = size( b )

Similarly, we get the size of matrix b and store it in r and s
Highlight

if ( m <> r ) then

error("Error: matrix A and vector b are incompatible sizes")

end

If the sizes of A and b are not compatible, we display an error on the console using error function.
Highlight

for k = 1 : 1 : m

indices = [ 1 : 1 : k-1, k+1 : 1 : m ]


// For all rows below and above the pivot, subtract a multiple

// of the pivoting row to get a zero

for i = indices

multiplier = C(i, k) / C(k,k)

for j = k+1 : n

C(i, j) = C(i, j) - multiplier * C(k, j)

end

end

end

Then we perform row operations to get diagonal form of the matrix.


Here pivot refers to the first non-zero element of a column.

Highlight

x = zeros( m, s )

Then we create a matrix of zeros called x with m rows and s columns.
Highlight

for i = 1 : 1 : m

for j = 1 : 1 : s

x(i, j) = C(i, m+j) / C(i, i)

end

end

Once we have the diagonal form,
  • we divide the right hand side part of augmented matrix
  • by the corresponding diagonal element
  • to get the value of each variable.


Highlight

x(i, j) = C(i, m+j) / C(i, i)

We store the value of each variable in x.
Highlight

return x

Then we return the value of x.


Highlight

endfunction

Finally, we end the function.
Click on Execute and select Save and Execute Now let us save and execute the function.
Type the following

[0.7, 1725;0.4352,-5.433]


The prompt requires us to enter the value of matrix A.


So we type

open square bracket zero point seven comma one seven two five semi colon

zero point four three five two comma minus five point four three three close square bracket.

Press Enter

Type the following

[1739;3.271]

The next prompt is for vector b.


So we type

open squre bracket one seven three nine semi colon

three point two seven one close square bracket

Press Enter

Type the following

GaussJordanElimination(A,b)

Then we call the function by typing

Gauss Jordan Elimination open paranthesis A comma b close paranthesis

Press Enter

Show answers on Scilab console The values of x one and x two are shown on the console.
Slide 14- Summary Let us summarize this tutorial.

In this tutorial, we have learnt to:

  • Develop Scilab code for solving system of linear equations
  • Find the value of the unknown variables of a system of linear equations
Show Slide 16

Title: About the Spoken Tutorial Project

  • It summarises the Spoken Tutorial project
  • If you do not have good bandwidth, you can download and watch it


* Watch the video available at the following link
  • It summarises the Spoken Tutorial project
  • If you do not have good bandwidth, you can download and watch it


Show Slide 17

Title: Spoken Tutorial Workshops

The Spoken Tutorial Project Team

  • Conducts workshops using spoken tutorials
  • Gives certificates for those who pass an online test
  • For more details, please write to contact@spoken-tutorial.org


The Spoken Tutorial Project Team
  • Conducts workshops using spoken tutorials
  • Gives certificates for those who pass an online test
  • For more details, please write to contact at spoken hyphen tutorial dot org


Show Slide 18

Title: Acknowledgement

  • Spoken Tutorial Project is a part of the Talk to a Teacher project
  • It is supported by the National Mission on Education through ICT, MHRD, Government of India
  • More information on this Mission is available at


* Spoken Tutorial Project is a part of the Talk to a Teacher project
  • It is supported by the National Mission on Education through ICT, MHRD, Government of India
  • More information on this Mission is available at
  • spoken hyphen tutorial dot org slash NMEICT hyphen Intro



This is mandatory. This is Ashwini Patil signing off. Thanks for joining.

Contributors and Content Editors

Lavitha Pereira, Nancyvarkey, Pratik kamble