Gauss Elimination Code - ANY SIZE - Python Code

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

OMGGG thank you!! I was searching for a code for so long but they were all kind of long and difficult to understand. This was so easy and helpful! You are a lifesaver

jahanvi
Автор

How can I get the augmented matrix from the user as input

siyabongabrian
Автор

Do you have any advice for swapping rows in a case where there are zeros on the diagonal but it would still be solvable with swaps?

wyattsullivan
Автор

do i need to install a library for it to work?

rubenpaul
Автор

Hi,

Could you please help me with solution for using GAuss Elimination python code for the below requirement?

Instructions
1. Use Python only. Do not use vectorized operations in Python, instead
use ’for loops’ wherever needed. Attach only the relevant data in your
submission and no need to submit the code, unless asked for.
2. By random entries, we mean a system generated random number. No
marks would be awarded for deterministic entries.


Q1) Implementing Gaussian Elimination Method
(i) Find the approximate time your computer takes for a single addition
by adding first 106 positive integers using a for loop and dividing the
time taken by 106. Similarly find the approximate time taken for a
single multiplication and division. Report the result obtained in the
form of a table. (0.5)
Deliverable(s): A tabular column indicating the time taken for each of
the operations
(ii) Write a function to implement Gauss elimination with and without pivoting.
Also write the code to count the number of additions, multiplications
and divisions performed during Gaussian elimination. Ensure
that the Gauss elimination performs 5S arithmetic which necessitates
5S arithmetic rounding for every addition, multiplication and division
performed in the algorithm. If this is not implemented correctly, the
rest of the answers will be considered invalid. Note that this is not
same as simple 5 digit rounding at the end of the computation. Do
not hardwire 5S arithmetic in the code and use dS instead. The code
can then be run with various values of d. (0.5 + 0.5)
Deliverable(s): The code for the Gaussian elimination with and without
partial pivoting with the rounding part
(iii) Generate random matrices of size n × n where n = 100, 200, . . ., 1000.
Also generate a random b ∈ Rn for each case. Each number must be
of the form m.dddd (Example : 4.5444) which means it has 5 Significant
digits in total. Perform Gaussian elimination with and without
partial pivoting for each n value (10 cases) above. Report the number
of additions, divisions and multiplications for each case in the form of
a table. No need of the code and the matrices / vectors. (0.5 + 0.5)
Deliverable(s): Two tabular columns indicating the number of additions,
multiplications and divisions for each value of n, for with and
without pivoting
(iv) Using the code determine the actual time taken for Gaussian elimination
with and without partial pivoting for the 10 cases and compare
this with the theoretical time. Present this data in a tabular form.
Assuming T1(n) is the actual time calculated for an n×n matrix, plot
a graphs of log(T1(n)) vs log(n) (for the 10 cases) and fit a straight line
to the observed curve and report the slope of the lines. Ensure that
separate graphs are to be plotted for the method with and without
partial pivoting. (0.5 + 1 + 1)
Deliverable(s):
(a) A table
S. No. n Actual time
with pivoting
Actual time
without
pivoting
Theoretical
time
(b) two log log plots and the slope in both the cases




Q2) Implementing Gauss Seidel and Gauss Jacobi Methods
(i) Write a function to check whether a given square matrix is diagonally
dominant or not. If not, the function should indicate if the matrix can
be made diagonally dominant by interchanging the rows? Code to be
written and submitted. (1)
Deliverable(s): The code
(ii) Write a function to generate Gauss Seidel iteration for a given square
matrix. The function should also return the values of 1, ∞ and Frobenius
norms of the iteration matrix. Generate a random 4 × 4 matrix.
Report the iteration matrix and its norm values returned by the function
along with the input matrix. (1)
Deliverable(s): The input matrix, iteration matrix and the three norms
obtained
(iii) Repeat part (ii) for the Gauss Jacobi iteration. (1)
Deliverable(s): The input matrix, iteration matrix and the three norms
obtained
(iv) Write a function that perform Gauss Seidel iterations. Generate a
random 4 × 4 matrix A and a suitable random vector b ∈ R4 and
2
report the results of passing this matrix to the functions written above.
Write down the first ten iterates of Gauss Seidel algorithm. Does it
converge? Generate a plot of ∥xk+1 − xk∥2 for the first 10 iterations.
Take a screenshot and paste it in the assignment document. (1)
Deliverable(s): The input matrix and the vector, the 10 successive
iterates and the plot
(v) Repeat part (iv) for the Gauss Jacobi method. (1)
Deliverable(s): The input matrix and the vector, the 10 successive
iterates and the plot
3

subhashrithyagutvs
welcome to shbcf.ru