Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

why is this code not working, I cannot figure out please help! import numpy as np # Given values x 1 = 2 . 9

why is this code not working, I cannot figure out please help! import numpy as np
# Given values
x1=2.95
x2=1.74
x3=-1.45
x4=1.32
# Constructing matrix A
A = np.array([[1,0,0,0],
[0,1,0,0],
[0,0,1,0],
[0,0,0,1],
[1,-1,0,0],
[1,0,-1,0],
[1,0,0,-1],
[0,1,-1,0],
[0,1,0,-1],
[0,0,1,-1]])
# Constructing vector b
b = np.array([x1, x2, x3, x4,1.23,4.45,1.61,3.21,0.45,-2.75],dtype=float)
def householder(A):
m, n = A.shape
Q = np.eye(m)
for k in range(n):
u = A[k:, k].copy()
u[0]+= np.sign(u[0])* np.linalg.norm(u)
u /= np.linalg.norm(u),
A[k:, k:]-=2.0* np.outer(u, u) @ A[k:, k:]
Q[k:, :]-=2.0* np.outer(u, u) @ Q[k:, :]
return Q
#Apply the Householder transformation to A
Q = householder (A)
R = Q % A
#Implement the backward substitution
def backwardSubstitution(A, b):
n = A.shape[1]
x = np.zeros(n)
for i in range(n -1,-1,-1):
x[i]=(b[i]- np.dot(A[i, i +1:], x[i +1:]))/ A[i, i]
return x
#tep 5: Solve for the best values of the altitudes using backward substitution.
x_hat = backwardSubstitution (R, Q.T @ b)
dx = x_hat - np.array ([x1, x2, x3, x4])
#Step 7: Print the required values
print("Matrix A:")
print(A)
print("
Calculated Altitudes (x_hat):")
print(x_hat)
print("
Differences (dx):")
print(dx)

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

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago