# Difference between revisions of "Assignment 2 - 2010 - Solution/Bonus question"

 ← Question 5 (previous step) Back to all questions

<rst> <rst-options: 'toc' = False/> <rst-options: 'reset-figures' = False/> Bonus question [1]

###### =======

Use the pseudo code developed in the course notes to write a MATLAB or Python function that implements Gauss elimination, without pivoting. The function should take :math:A and :math:b as inputs, and return vector :math:x.

Use your function to solve this set of equations from question 1, and print the update :math:A matrix and :math:b vector after every pivot step.

Solution

A function that implements the Gauss elimination without pivoting is provided below.

.. twocolumncode::

   :code1: ../che3e4/Assignments/Assignment-2/code/guass.m
:language1: matlab
:code2: ../che3e4/Assignments/Assignment-2/code/guass.py
:language2: python


Now we use this function to solve the system of equations in Question 1. The commented lines in the MATLAB code show how the function is used. The results are: :math:x =[1.3333, 3.1667,1.5000,-6.0000]. Also, the :math:A and :math:b (denoted as :math:C=[A\quad b] below) are updated as:

   .. math::
C^1=        \left[ \begin{array}{ccccc}          1  &   1  &   1  &   1  &   0\\          0  &  -3  &  -3  &  -3  &   4\\          0  &   3  &  -5  &   0  &   2\\          0  &  -6 &   -6  &  -4  &  -4        \end{array} \right]

   .. math::
C^2=        \left[ \begin{array}{ccccc}             1  &   1  &   1  &   1 &   0\\             0  &  -3  &  -3  &  -3 &  4\\             0  &   0  &  -8  &  -3 &  6\\             0  &   0  &   0  &   2 &  -12        \end{array} \right]

   .. math::
C^3=        \left[ \begin{array}{ccccc}          1  &   1   &   1  &   1  &  0\\          0  &  -3   &  -3  &  -3  &  4\\             0  &   0   &  -8  &  -3  &  6\\             0  &   0   &   0  &   2  & -12        \end{array} \right]



The final result for :math:x = [1.333, 3.167, 1.5, -6].

</rst>

 ← Question 5 (previous step) Back to all questions