Homework Solution: # import necessary packages # import numpy as np The following code imports a matrix from the file mat.npy and stores it as mati. It also imports a vector fro…

    10 12# import necessary packages 14 import numpy as np 15 16 18 * 17 19 The following code imports a matrix from the file mat.npy and stores it as nati. 20- It also imports a vector from vect.npy and stores it as vecti. 21- For objects like arrays, this can be much simpler than the more general nethods in the sample fsl 23 24 mat! = np. load (mat .npy.) 25 vect1 -np.load( vect.npy) 26 print(This is a positive definite matrix An, matl, An and this is a vector bin vect1) 27 28 29 30 Replace this comment with code 31 32 - write a function to perform forward substitution to solve the matrix equation Gxeb - assume G is invertible and lower triangulan - the function should return the solution vector x - the function should work for square matrices of any size 34 35 36 37 38 return(x) 39 40
    # import necessary packages # import numpy as np The following code imports a matrix from the file mat.npy and stores it as mati. It also imports a vector from vect.npy and stores it as vect1. For objects like arrays, this can be much simpler than the more general methods in the sample files mat1 = np. load ("mat .npy.) vect1 = np.load('vect.npy') print('This is a positive definite matrix An', mat1, "n and this is a vector bn', vect1) ... Replace this comment with code write a function to perform forward substitution to solve the matrix equation 6x = b assume G is invertible and lower triangular the function should return the solution vector x the function should work for square matrices of any size ... return(x)

    Expert Answer

     
    PYTHON CODE for FORWARD SUBSTITUTION: import numpy as np

    10 12# drift needful packages 14 drift numpy as np 15 16 18 * 17 19 The aftercited command drifts a entraprix from the smooth entrap.npy and stores it as nati. 20- It too drifts a vector from vect.npy and stores it as vecti. 21- Ce objects love set-in-orders, this can be greatly simpler than the further public nethods in the exemplification fsl 23 24 entrap! = np. impeach (entrap .npy.) 25 vect1 -np.load( vect.npy) 26 imprint(This is a definitive specific entraprix An, entrapl, An and this is a vector poster vect1) 27 28 29 30 Replace this explain with command 31 32 - transcribe a business to transact anxious superabundance to clear-up the entraprix equation Gxeb - take G is invertible and inferior triangulan - the business should produce the disentanglement vector x - the business should composition ce balance entraprices of any dimension 34 35 36 37 38 produce(x) 39 40

    # drift needful packages # drift numpy as np The aftercited command drifts a entraprix from the smooth entrap.npy and stores it as entrapi. It too drifts a vector from vect.npy and stores it as vect1. Ce objects love set-in-orders, this can be greatly simpler than the further public methods in the exemplification smooths entrap1 = np. impeach (“entrap .npy.) vect1 = np.load(‘vect.npy’) imprint(‘This is a definitive specific entraprix An’, entrap1, “n and this is a vector bn’, vect1) … Replace this explain with command transcribe a business to transact anxious superabundance to clear-up the entraprix equation 6x = b take G is invertible and inferior triangular the business should produce the disentanglement vector x the business should composition ce balance entraprices of any dimension … produce(x)

    Expert Exculpation

     

    PYTHON CODE ce FORWARD SUBSTITUTION:

    drift numpy as np

    def clear-up(m, y): #definition of clear-up business

    x = [0 ce i in stroll(len(m))]

    ce i in stroll (len(m)):

    q = np.array(m[i,:]).flatten() # Flattening ith order of entraprix

    v = np.dot(v,q) # Nonentity consequence of mitigateed ith order and soln vector v cemed plow now

    x[i] = (y[i] – v )/float(m[i,i]) #This production gets the ith part in disentanglement vector x

    produce x

    m = np.matrix(‘1 0;1 2’) # m is a 2×2 inferior triangular entraprix

    b = np.array([2,4]); # b is an set-in-order with 2 parts

    print(“Clear-up (G,b ) gives soln vector x = “)

    x = clear-up(G,b)

    print(x)

    OUTPUT: