Transcribed TextTranscribed Text

Write function gaussElim(A,b) for solving a system of simultaneous equations Ax = b using Gauss elimination with partial pivoting. The input parameters to the function are the square matrix, A, and the column vector b. The function should return the solution to the simultaneous equations. In addition, the function should not change the input matrix in the process of solving the equations. Test your program using the following problems. You can check your work by solving the problems using a NumPy function (e.g. x = np.linalg.solve(A,b)) (2x+y-z=1.0 - = 2x + y - 2z = - 2 x - y + Z = 2 # main # This represents a set of 6 simultaneous equations. Mrx = np.array([ [1.0,3,2,4,3,1], (-4,0,3,2,3,4], [3,-1,3,2,2,5], [3,3,12,2,- - 6,-4], [-1,-2,-3,7,6,4], [7,5,0,0,4,2] ]) Rhs = np.array([[ 4, 5, 6, 10, 6, - -8 ]]) S = gaussElim(Mrx,Rhs.T) print(s) You can use the following code to return only the last columns of the reduced matrix A return A[:, nc-1] # extracts the last column of the matrix or return A[:, nr : nc] # extracts the last columns of the matrix. This works best if you have multiple constant columns

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import numpy as np

def gaussElim(A, b):
    This function solves system of linear equations Ax = b using Gauss elimination with
    partial pivoting. Input parameters are:

    A - square matrix
    b - column vector
    We will assume that A is singular matrix so that sysyem has unique solution. Output is:
    solution - solution to the system, row vector
    # number of equations
    A_rows = len(A)

    # append the column b to the right side of the matrix A so we obtain n x n+1 matrix A_tilde
    A_tilde = np.c_[A, b]

    Find the index of the entry in each colum with the largest absolute value. This entry is called the pivot.
    We assumed that pivot it is not equal to 0, othervise the matrix A is singular.
    Bring the row with pivot to the diagonal i.e interchange rows k and P_k
    for k in range(A_rows):
       for P_k in range(k, A_rows):
            if abs(A_tilde[P_k, k]) > abs(A_tilde[k, k]):
                A_tilde[[k, P_k]] = A_tilde[[P_k, k]]
       Iterate over rows below the pivot and calculate the factor temp_ in order to make the k-th entry zero.
       Further, subtract the temp-th multiple of corresponding element in k-th row for every...

By purchasing this solution you'll be able to access the following files:

for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats