https://script.spoken-tutorial.org/index.php?title=Scilab/C4/Linear-equations-Iterative-Methods/English&feed=atom&action=history
Scilab/C4/Linear-equations-Iterative-Methods/English - Revision history
2024-03-28T20:30:12Z
Revision history for this page on the wiki
MediaWiki 1.23.17
https://script.spoken-tutorial.org/index.php?title=Scilab/C4/Linear-equations-Iterative-Methods/English&diff=8471&oldid=prev
Nancyvarkey at 16:51, 1 February 2014
2014-02-01T16:51:18Z
<p></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr style='vertical-align: top;'>
<td colspan='2' style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black; text-align: center;">Revision as of 16:51, 1 February 2014</td>
</tr><tr><td colspan="2" class="diff-lineno">Line 61:</td>
<td colspan="2" class="diff-lineno">Line 61:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>Here '''e '''denotes the answer should be in '''scientific notation''' <del class="diffchange diffchange-inline">and </del>twenty specifies the number of digits to be displayed.</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>Here '''e '''denotes the answer should be in '''scientific notation'''<ins class="diffchange diffchange-inline">.</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">And '''</ins>twenty<ins class="diffchange diffchange-inline">''' </ins>specifies the number of digits to be displayed.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>|-</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>|-</div></td></tr>
<tr><td colspan="2" class="diff-lineno">Line 86:</td>
<td colspan="2" class="diff-lineno">Line 88:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>'''<nowiki>[m, n] = size( A )</nowiki>'''</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>'''<nowiki>[m, n] = size( A )</nowiki>'''</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|Then we use''' size '''function to check if '''A matrix is a square matrix.'''</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|Then we use''' size '''function to check if '''A matrix<ins class="diffchange diffchange-inline">''' </ins>is a <ins class="diffchange diffchange-inline">'''</ins>square matrix.'''</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td colspan="2" class="diff-lineno">Line 114:</td>
<td colspan="2" class="diff-lineno">Line 116:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* We then check if '''matrix A''' is '''diagonally dominant'''.</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* We then check if '''matrix A''' is '''diagonally dominant'''.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* The first half calculates the sum of each row of the '''matrix'''.</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* The first half calculates the sum of each row of the '''matrix'''.</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* Then it checks if twice the product of the diagonal element is greater than the sum of the elements of that row.</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* Then it checks if twice the product of the <ins class="diffchange diffchange-inline">'''</ins>diagonal element<ins class="diffchange diffchange-inline">''' </ins>is greater than the sum of the elements of that row.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* If it isn't, an error is displayed using '''error function'''.</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* If it isn't, an error is displayed using '''error function'''.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td colspan="2" class="diff-lineno">Line 121:</td>
<td colspan="2" class="diff-lineno">Line 123:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>'''<nowiki>function [ solution ] = JacobiIteration( A, b, x0, MaxIter, tol )</nowiki>'''</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>'''<nowiki>function [ solution ] = JacobiIteration( A, b, x0, MaxIter, tol )</nowiki>'''</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>| 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 '''Jacobi Iteration''' with input arguments '''A, b , x zero, maximum iteration and tolerance level'''.</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>| 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 '''Jacobi Iteration''' with input arguments  </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>'''A, b , x zero,<ins class="diffchange diffchange-inline">'''</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">''' </ins>maximum iteration and tolerance level'''.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td colspan="2" class="diff-lineno">Line 171:</td>
<td colspan="2" class="diff-lineno">Line 176:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>'''endfunction'''</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>'''endfunction'''</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* We calculate the value for''' x k p one''' and then check if the '''relative error is lesser than tolerance level.'''</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* We calculate the value for''' x k p one''' and then check if the '''relative error<ins class="diffchange diffchange-inline">''' </ins>is lesser than <ins class="diffchange diffchange-inline">'''</ins>tolerance level.'''</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* If it is lesser than '''tolerance level''', we break the iteration and the solution is returned.</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* If it is lesser than '''tolerance level''', we break the iteration and the solution is returned.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* Finally we end the function.</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* Finally we end the function.</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>|-</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>|-</div></td></tr>
<tr><td colspan="2" class="diff-lineno">Line 207:</td>
<td colspan="2" class="diff-lineno">Line 221:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>Initial approximation nx1: '''<nowiki>[1;1]</nowiki>'''</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>Initial approximation nx1: '''<nowiki>[1;1]</nowiki>'''</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| <del class="diffchange diffchange-inline">* </del>The '''initial values matrix''' is '''open square bracket one semi colon one close square bracket'''</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The '''initial values matrix''' is '''open square bracket one semi colon one close square bracket'''</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>Press '''Enter'''.</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>Press '''Enter'''.</div></td></tr>
<tr><td colspan="2" class="diff-lineno">Line 241:</td>
<td colspan="2" class="diff-lineno">Line 255:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>The values for '''x one''' and '''x two''' are shown on the '''console'''.  </div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>The values for '''x one''' and '''x two''' are shown on the '''console'''.  </div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">The number of iterations are also shown.</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>|-</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>|-</div></td></tr>
<tr><td colspan="2" class="diff-lineno">Line 375:</td>
<td colspan="2" class="diff-lineno">Line 391:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* At each iteration, the value of '''x k p one''' gets updated.</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* At each iteration, the value of '''x k p one''' gets updated.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* Also, we check if '''relative error''' is lesser than specified '''tolerance level'''.</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* Also, we check if '''relative error''' is lesser than specified '''tolerance level'''.</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* If it is, we <del class="diffchange diffchange-inline">'''</del>break the iteration<del class="diffchange diffchange-inline">'''</del>.</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* If it is, we break the iteration.</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* Then equate '''x k p one''' to the variable solution.</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* Then equate '''x k p one''' to the variable <ins class="diffchange diffchange-inline">'''</ins>solution<ins class="diffchange diffchange-inline">'''</ins>.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* Finally, we end the function.</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>* Finally, we end the function.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td colspan="2" class="diff-lineno">Line 447:</td>
<td colspan="2" class="diff-lineno">Line 463:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| <del class="diffchange diffchange-inline">* </del>Finally we call the function by typing</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|Finally we call the function by typing</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>''' G a u s s S e i d e l open paranthesis A comma b comma x zero comma M a x I t e r comma t o l close paranthesis'''</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>''' G a u s s S e i d e l open paranthesis A comma b comma x zero comma M a x I t e r comma t o l close paranthesis'''</div></td></tr>
</table>
Nancyvarkey
https://script.spoken-tutorial.org/index.php?title=Scilab/C4/Linear-equations-Iterative-Methods/English&diff=8051&oldid=prev
Nancyvarkey at 13:56, 27 December 2013
2013-12-27T13:56:05Z
<p></p>
<a href="https://script.spoken-tutorial.org/index.php?title=Scilab/C4/Linear-equations-Iterative-Methods/English&diff=8051&oldid=7899">Show changes</a>
Nancyvarkey
https://script.spoken-tutorial.org/index.php?title=Scilab/C4/Linear-equations-Iterative-Methods/English&diff=7899&oldid=prev
Lavitha Pereira: Created page with ''''Title of script''': Solving System of Linear Equations using Iterative Methods '''Author: Shamika''' '''Keywords: System of linear equations, Iterative Methods''' {| styl…'
2013-12-18T05:02:21Z
<p>Created page with ''''Title of script''': Solving System of Linear Equations using Iterative Methods '''Author: Shamika''' '''Keywords: System of linear equations, Iterative Methods''' {| styl…'</p>
<p><b>New page</b></p><div>'''Title of script''': Solving System of Linear Equations using Iterative Methods<br />
<br />
'''Author: Shamika'''<br />
<br />
'''Keywords: System of linear equations, Iterative Methods'''<br />
<br />
<br />
<br />
{| style="border-spacing:0;"<br />
! <center>Visual Cue</center><br />
! <center>Narration</center><br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 1<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Dear Friends,<br />
<br />
Welcome to the Spoken Tutorial on “'''Solving System of Linear Equations using Iterative Methods'''”<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 2 -Learning Objective Slide<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| At the end of this tutorial, you will learn how to:<br />
<br />
* Solve system of linear equations using iterative methods<br />
* Develop Scilab code to solve linear equations<br />
<br />
<br />
<br />
|-<br />
| 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<br />
| 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 with '''Scilab 5.3.3''' version<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 4- Prerequisites slide<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Before practising this tutorial, a learner should have basic knowledge of '''Scilab and Solving Linear Equations'''<br />
<br />
<br />
For Scilab, please refer to the relevant tutorials available on the '''Spoken Tutorial '''website.<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 5- Jacobi Method<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * The first iterative method we will be studying is '''Jacobi method.'''<br />
* Given a '''system of linear equations, with n equations and n unknowns'''<br />
* We rewrite the equations such tha'''t 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'''<br />
* We assume values for each''' x of i'''<br />
* Then we substitute the values in the equations obtained in the previous step.<br />
* We continue the iteration until the solution converges.<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 6- Example<br />
| 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 '''Jacobi Method'''<br />
<br />
<br />
<br />
|-<br />
| 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 JacobiIteration_final.sci<br />
| 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 for '''Jacobi Method'''.<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight<br />
<br />
'''format('e',20)'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * We use '''format''' method to specify the format of the displayed answers on the Scilab console.<br />
* Here '''e '''denotes the answer should be in '''scientific notation''' and '''twenty''' specifies the number of digits to be displayed.<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight<br />
<br />
'''A=input("Enter the coeffiecient matrix of nxn: ")'''<br />
<br />
'''b=input("Enter the right-hand side matrix nx1: ")'''<br />
<br />
'''x0=input("Initial approximation nx1: ")'''<br />
<br />
'''MaxIter=input("Maximum no. of iterations: ")'''<br />
<br />
'''tol=input("Enter the convergence tolerance :")//stop if norm <nowiki>change in x < tol</nowiki>'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Then we use '''input''' function to get the values for the '''matrices coefficient matrix, right hand side matrix, initial values matrix, maximum number of iteration and convergence tolerance'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight<br />
<br />
'''<nowiki>[m, n] = size( A )</nowiki>'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Then we use''' size '''function to check if '''A matrix is a square matrix.'''<br />
* If it isn't, we use '''error function''' to display an error<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight<br />
<br />
'''for i=1:1:m'''<br />
<br />
'''sum=0;'''<br />
<br />
'''for j=1:1:m'''<br />
<br />
'''sum=sum+abs(A(i,j));'''<br />
<br />
'''end'''<br />
<br />
'''<nowiki>if 2*abs(A(i,i))<sum then</nowiki>'''<br />
<br />
'''error("the matrix is not diagonally dominant")'''<br />
<br />
'''end'''<br />
<br />
'''end'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * We then check if matrix A is '''diagonally dominant'''.<br />
* The first half calculates the sum of each row of the matrix.<br />
* Then it checks if the twice the product of the diagonal element is greater than the sum of the elements of that row.<br />
* If it isn't, an error is displayed using '''error function'''.<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight<br />
<br />
'''<nowiki>function [ solution ] = JacobiIteration( A, b, x0, MaxIter, tol )</nowiki>'''<br />
| 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 '''Jacobi Iteration''' with input arguments '''A, b , x zero, maximum iteration and tolerance level'''.<br />
* Here '''x zero''' is the '''initial values matrix'''.<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight<br />
<br />
'''if ( length(x0) ~= n )'''<br />
<br />
'''error( "Sizes of input matrix and input vector do not match" )'''<br />
<br />
'''end'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * We check if the size of A matrix and initial values matrix are compatible with each other.<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight<br />
<br />
'''xk = x0'''<br />
<br />
'''for k = 1 : 1 : MaxIter'''<br />
<br />
'''for i = 1 : n'''<br />
<br />
'''xkp1( i ) = (b(i) - A(i, 1:i-1)*xk(1:i-1) - A(i, i+1:n)*xk(i+1:n)) / A(i,i) //Computes the jacobian updates'''<br />
<br />
'''end'''<br />
<br />
<br />
'''RelativeError = norm( xkp1 - xk, 'inf' ) / norm( xkp1, 'inf' )'''<br />
<br />
'''printf( "iter = %d, Relative Error = %g\n", k, RelativeError )'''<br />
<br />
'''xk = xkp1'''<br />
<br />
<br />
'''<nowiki>if ( RelativeError < tol )</nowiki>'''<br />
<br />
'''break'''<br />
<br />
'''end'''<br />
<br />
'''end'''<br />
<br />
<br />
'''solution = xkp1'''<br />
<br />
<br />
'''endfunction'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * We calculate the value for''' x k p one''' and then check if the '''relative error is lesser than tolerance level.'''<br />
* If it is lesser than '''tolerance level''', we break the iteration and the solution is returned.<br />
* Finally we '''end the function'''<br />
<br />
<br />
<br />
|-<br />
| 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<br />
| 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 function'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Switch to Scilab console<br />
| 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'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Enter these values on Scilab console for each prompt<br />
<br />
Enter the coeffiecient matrix of nxn: '''<nowiki>[2 1;5 7]</nowiki>'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Let us enter the values at each prompt.<br />
<br />
* The '''coefficient matrix A is '''<br />
* '''open square bracket two space one '''<br />
* '''semi colon '''<br />
* '''five space seven close square bracket'''<br />
* '''Press enter'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Type<br />
<br />
Enter the right-hand side matrix nx1: '''<nowiki>[11; 13]</nowiki>'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Then we type<br />
* '''open square bracket eleven '''<br />
* '''semicolon '''<br />
* '''thirteen'''<br />
* '''press enter'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Type<br />
<br />
Initial approximation nx1: '''<nowiki>[1;1]</nowiki>'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * The initial values matrix is <br />
* '''open square bracket one '''<br />
* '''semi colon '''<br />
* '''one close square bracket'''<br />
* '''press enter'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Type<br />
<br />
Maximum no. of iterations: '''25'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * The maximum number of iterations is''' twenty five'''<br />
* '''press enter'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Type<br />
<br />
Enter the convergence tolerance :'''0.00001'''<br />
<br />
<br />
<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Let the convergence tolerance level be''' zero point zero zero zero zero one'''<br />
* '''press enter'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Type:<br />
<br />
'''JacobiIteration( A, b, x0, MaxIter, tol )'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * We call the function by typing '''Jacobi Iteration open paranthesis A comma b comma x zero comma M a x I t e r comma t o l close paranthesis'''<br />
* '''Press Enter'''<br />
* The values for '''x one''' and '''x two''' are shown on the console. <br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 7- Gauss Seidel Method<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Let us now study Gauss Seidel method. <br />
* Given a '''system of linear equations, with n equations and n unknows'''<br />
* We rewrite the equations for each unknown, '''by subtracting the other variables and their coefficients from the corresponding right hand side element.'''<br />
* Then we divide this '''by the coefficient a i i of the unknown variable for that variable'''.<br />
* This is done for every given equation.<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 8- Gauss Seidel<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * 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'''<br />
* In '''Gauss Seidel method''', we '''over write the value of x of i k with x of i k plus one'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 9- Example<br />
| 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 Seidel Method'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Switch to Scilab editor and open GaussSeidel.sci<br />
<br />
<br />
<br />
| 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 for '''Gauss Seidel Method'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight<br />
<br />
'''format('e',20)'''<br />
<br />
<br />
<br />
| 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 specifies the format of the displayed answer on the console using '''format function'''.<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight<br />
<br />
'''A=input("Enter the coeffiecient matrix of nxn: ")'''<br />
<br />
'''b=input("Enter the right-hand side matrix nx1: ")'''<br />
<br />
'''x0=input("Initial approximation nx1: ")'''<br />
<br />
'''MaxIter=input("Maximum no. of iterations: ")'''<br />
<br />
'''tol=input("Enter the convergence <nowiki>tolerance :")//stop if norm change in x < tol</nowiki>'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Then we use '''input function''' to get the values of '''coefficient matrix, right hand side matrix, initial values of the variables matrix, maximum number of iteration and tolerance level'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight<br />
<br />
'''<nowiki>function [ solution ] = GaussSeidel( A, b, x0, MaxIter, tol )</nowiki>'''<br />
| 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 '''Gauss Seidel '''with''' input arguments A comma b comma x zero comma Max Iterations '''and '''tolerance level''' and output argument solution<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight<br />
<br />
'''// Check that the matrix is square'''<br />
<br />
'''<nowiki>[m, n] = size( A )</nowiki>'''<br />
<br />
'''if ( m ~= n )'''<br />
<br />
'''error( "The input matrix is not square" )'''<br />
<br />
'''end'''<br />
<br />
<br />
'''// Check that the initial vector is of the same size'''<br />
<br />
'''if ( length(x0) ~= n )'''<br />
<br />
'''error( "Sizes of input matrix and input vector do not match" )'''<br />
<br />
'''end'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * We check if '''matrix A is square''' and the sizes of '''initial vector and matrix A''' are compatible using''' size and length function'''.<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight<br />
<br />
'''xk = x0'''<br />
<br />
'''xkp1 = zeros( xk )'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Then we start the iterations. We equate the '''initial values vector x zero to x k.'''<br />
* We create a '''matrix of zeros with the same size of x k and call it x k p one.'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Highlight<br />
<br />
for k = 1 : 1 : MaxIter<br />
<br />
<br />
'''// Computes the Gauss-Seidel update'''<br />
<br />
'''for i = 1 : n'''<br />
<br />
'''xkp1( i ) = (b(i) - A(i, 1:i-1)*xkp1(1:i-1) - A(i,i+1:n)*xk(i+1:n)) / A(i,i)'''<br />
<br />
'''// x^{k+1}'''<br />
<br />
'''end'''<br />
<br />
'''// Applies the relaxation'''<br />
<br />
'''RelativeError = norm( xkp1 - xk, 'inf' ) / norm( xkp1, 'inf' )'''<br />
<br />
'''printf( "iter = %d, Relative Error = %g\n", k, RelativeError )'''<br />
<br />
'''xk = xkp1'''<br />
<br />
'''<nowiki>if ( RelativeError < tol )</nowiki>'''<br />
<br />
'''break'''<br />
<br />
'''end'''<br />
<br />
'''end'''<br />
<br />
<br />
'''solution = xkp1'''<br />
<br />
<br />
'''endfunction'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * We solve for each equation to get the value of the unknown variable for that equation using '''x k p one'''.<br />
* At each iteration, the value of '''x k p one''' gets updated.<br />
* Also, we check if '''relative error is lesser than specified tolerance level'''.<br />
* If it is, we '''break the iteration'''.<br />
* Then '''equate x k p one to the variable solution'''.<br />
* Finally, we '''end the function'''<br />
<br />
<br />
<br />
|-<br />
| 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<br />
| 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 function'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Switch to Scilab console<br />
| 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'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Type the following on Scilab console:<br />
<br />
For first prompt<br />
<br />
'''<nowiki>[2 1;5 7]</nowiki>'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * For the first prompt we type '''matrix A.'''<br />
<br />
* Type <br />
* '''open square bracket two space one '''<br />
* '''semi colon '''<br />
* '''five space seven close square bracket'''<br />
* '''Press enter'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Second prompt<br />
<br />
'''<nowiki>[11; 13]</nowiki>'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * For the next prompt, type<br />
* '''left square bracket eleven'''<br />
* '''semi colon'''<br />
* '''thirteen right square bracket'''<br />
* '''Press enter'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| For third prompt<br />
<br />
'''<nowiki>[1;1]</nowiki>'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * We provide the values of '''initial value vector '''by typing <br />
* '''open square bracket one '''<br />
* '''semicolon '''<br />
* '''one close square bracket'''<br />
* '''Press enter'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| For fourth prompt<br />
<br />
'''25'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Then we specify the''' maximum number of iterations to be twenty five'''<br />
* '''Press enter'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| For fifth prompt<br />
<br />
'''0.00001'''<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Let us define tolerance level to be''' zero point zero zero zero zero one'''<br />
* '''Press enter'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Then type:<br />
<br />
'''GaussSeidel( A, b, x0, MaxIter, tol )'''<br />
<br />
<br />
<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Finally we call the function by typing''' G a u s s S e i d e l open paranthesis A comma b comma x zero comma M a x I t e r comma t o l close paranthesis'''<br />
* '''Press enter'''<br />
* The values of '''x one and x two '''are displayed.<br />
* The number of iterations to solve the same problem are lesser than '''Jacobi method'''<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 13- Solve<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Solve this problem on your own using '''Jacobi and Gauss Seidel '''methods<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide 14- Summary<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| In this tutorial, we have learnt to:<br />
<br />
* Develop '''Scilab code''' for solving system of linear equations<br />
* Find the value of the unknown variables of a system of linear equations<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| '''Show Slide 15'''<br />
<br />
'''Title: About the Spoken Tutorial Project'''<br />
<br />
* Watch the video available at [http://spoken-tutorial.org/What_is_a_Spoken_Tutorial http://spoken-][http://spoken-tutorial.org/What_is_a_Spoken_Tutorial tutorial.org/What_is_a_Spoken_Tutorial]<br />
<br />
* It summarises the Spoken Tutorial project<br />
<br />
* If you do not have good bandwidth, you can download and watch it<br />
<br />
<br />
| 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 />
<br />
* Watch the video available at the following link<br />
<br />
* It summarises the Spoken Tutorial project<br />
<br />
* If you do not have good bandwidth, you can download and watch it<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| '''Show Slide 16'''<br />
<br />
'''Title: Spoken Tutorial Workshops'''<br />
<br />
The Spoken Tutorial Project Team<br />
<br />
* Conducts workshops using spoken tutorials<br />
<br />
* Gives certificates for those who pass an online test<br />
<br />
* For more details, please write to contact@spoken-tutorial.org<br />
<br />
<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The Spoken Tutorial Project Team<br />
<br />
* Conducts workshops using spoken tutorials<br />
<br />
* Gives certificates for those who pass an online test<br />
<br />
* For more details, please write to contact at spoken hyphen tutorial dot org<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| '''Show Slide 17'''<br />
<br />
'''Title: Acknowledgement'''<br />
<br />
* Spoken Tutorial Project is a part of the Talk to a Teacher project<br />
<br />
* It is supported by the National Mission on Education through ICT, MHRD, Government of India<br />
<br />
* More information on this Mission is available at<br />
<br />
* [http://spoken-tutorial.org/NMEICT-Intro http://spoken-tutorial.org/NMEICT-][http://spoken-tutorial.org/NMEICT-Intro Intro]<br />
<br />
<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * Spoken Tutorial Project is a part of the Talk to a Teacher project<br />
* It is supported by the National Mission on Education through ICT, MHRD, Government of India<br />
* More information on this Mission is available at<br />
* spoken hyphen tutorial dot org slash NMEICT hyphen Intro<br />
<br />
<br />
<br />
|-<br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| <br />
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| * This is Ashwini Patil signing off. Thank you for joining. <br />
<br />
<br />
<br />
|}</div>
Lavitha Pereira