hafizas101
hafizas101

Reputation: 11

Re orthogonalization of vector with respect to matrix

I have a matrix A of size 50 X 6 and I have a vector x of size 50 X 1. Assume that all columns of A are orthogonal to each other. I have 2 questions:

  1. What is the best way to check whether x is orthogonal to all columns of A or not ? Only solution I can think of is to iterate through every column of A and calculate dot product.

  2. Suppose that from dot products I find that x is not orthogonal to 3rd and 5th column of A then how can I orthogonalize x with respect to all columns of A ?

Thank you for your attention.

Upvotes: 1

Views: 482

Answers (2)

user19703799
user19703799

Reputation: 1

  1. You need to compute XT.A which is matrix multiplication of x transpose and A. It will result a row vector of size 6x1. Iff all the element of result vectors are zero then x is orthogonal to all the columns of A.

  2. For part two you need use Graam schmidt technique, only thing special in your case is few term of orthogonality calculation will zero, becoz they are orthogonal,

Upvotes: 0

Ahmed Fasih
Ahmed Fasih

Reputation: 6927

  1. The best way to check whether x is orthogonal to every column of A is, like you say, check every column. Luckily, matrix multiplication is the fastest, most heavily optimized operation in all of numerical computing, so A * x is probably going to be fast enough!
  2. About #2, this is the basic idea in Gram-Schmidt orthonormalization. You just have to subtract the piece of x that's represented by the columns of A. In code (sorry I only use Numpy/Python but the same ideas apply to Matlab!):
import numpy as np

# just for demo purposes: build A and x
from scipy.linalg import qr # easy way to generate orthonormal columns
A = qr(np.random.randn(50, 6))[0][:, :6]
x = np.random.randn(50, 1)

# now, #1
is_x_orthogonal = np.allclose(A.T @ x, 0) # False :(

# and now, #2
newx = A @ (A.T @ x) - x

is_newx_orthogonal = np.allclose(A.T @ newx, 0) # True :D

Upvotes: 0

Related Questions