Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello. I have this python code (bellow) and I need to calculate, still in python

ID: 3855941 • Letter: H

Question

Hello. I have this python code (bellow) and I need to calculate, still in python, the condition number of V and U and the number of digits that will be lost obtaining the coefficients of the corresponding polynomials.

import random import numpy as np k = 2 # number of equally spaced elements space = 0.3 #value of the spacing between equally spaced elements x = [i"space for i in range(k)] #equally spaced xk elements for i in range(k,6): x.append(-1l+random.random0 ) #randomly spaced rest of the elements y = [np.exp(i) for i imx] #np.sinO, np.cos(), np.expl, np.log0, np.log100, np.logo can be used V = np.vander(x) #constructs vandermonde matrix of the vector X. U = np.vander(y) #constructs vandermonde matrix of the vector 'y.

Explanation / Answer

import random
import numpy as np
from numpy import linalg as LA
k = 2
space = 0.3
x = [i*space for i in range(k)]
for i in range(k, 6):
   x.append(x[i-1]+random.random())

y = [np.exp(i) for i in x]

V = np.vander(x)
U = np.vander(y)

condV = LA.cond(V)
condU = LA.cond(U)

msgV = 'Condition number of V is ' + str(condV)
msgU = 'Condition number of U is ' + str(condU)

print(msgV)
print(msgU)

OUTPUT:

$ python3 conditionnumber.py
Condition number of V is 10863.0533979
Condition number of U is 8592247.69874