Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Develop a python implementation of Gaussian elimination using partial pivoting. Develop a python code reducing echelon matrices to their reduced echelon forms. You can use

Develop a python implementation of Gaussian elimination using partial pivoting.
Develop a python code reducing echelon matrices to their reduced echelon forms.
You can use the python functions in the attached file. The shorter and smarter the python codes, the higher the grades.
Finding the bugs and the shortcomings of the attached example code will increase your grade.
import numpy as np
from scipy import linalg
def eliminateCol(A, k=0):
# guarantee that A is float type
if A.dtype.kind !='f' and A.dtype.kind !='c': return None
# load dimensions
dim0,dim1= np.shape(A)
# initialize outputs
swap = np.identity(dim0,dtype=float)
oper = np.identity(dim0,dtype=float)
# k < dim1
k = k%dim1
# if the column k is zero column, return
if A[:,k].any()== False: return swap,oper
i0=0
if k !=0:
# find a row i0 whose left most k-1 entries are all zero
while i0< dim0:
if A[i0,0:k].any()== False: break
i0+=1
# find a nonzero element A[i,k] to use as a pivot
i = i0;
while i < dim0:
if A[i,k]!=0: break
i+=1
if i == dim0: return swap,oper
# swap the row i with the row i0
if i != i0: A[[i0,i],]= A[[i,i0],];swap[[i0,i],]= swap[[i,i0],]
# row i0 is the pivot row and A[j,k] is zero for i0=0:
if A[i,j]!=0:
quot = A[i,j]/ A[k,j]
A[i,:]= A[i,:]- quot*A[k,:]
oper[i,k]=-quot
i-=1
return oper
def eliminateScale(A):
# guarantee that A is float type
if A.dtype.kind !='f' and A.dtype.kind !='c': return None
# load dimensions
dim0,dim1= np.shape(A)
# initialize outputs
oper = np.identity(dim0,dtype=float)
# find pivots
i =0
while i < dim0:
j =0
while j < dim1:
if A[i,j]==0: j+=1; continue
else:
oper[i,i]=1/A[i,j]
A[i,j:]= A[i,j:]/A[i,j]
break
j+=1
i+=1
return oper

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

@ It's unwise to compete with the cottage industries of Asia.

Answered: 1 week ago

Question

=+b) Identify all the factor levels.

Answered: 1 week ago

Question

Define Administration and Management

Answered: 1 week ago