v1 = x ∥x∥2 , w2 = y − αv1, v2 = w2 ∥w2∥2 . find the formula for α such that (v1, w2) = (v1, v2) = 0. then, v1, v2 form a unit orthogonal basis for the sub-space spanned by x and y in matlab

Given the formulas v1 = x ∥x∥2 and w2 = y − αv1, we can define v2 = w2 ∥w2∥2. We need to find the formula for α such that (v1, w2) = (v1, v2) = 0.

The dot product between v1 and w2 can be written as:

(v1, w2) = (x ||x||^2, y - αv1) = (x, y) ||x||^2 - α||x||^4

The dot product between v1 and v2 can be written as:

(v1, v2) = (x ||x||^2, w2 ||w2||^2) = (x, y - αv1) ||y - αv1||^2 = (x, y - αv1) (y - αv1) /||(y - αv1)||^2

We want (v1, w2) = (v1, v2) = 0. Therefore, we need to solve the system of equations:

(x, y) ||x||^2 - α||x||^4 = 0 (x, y - αv1) (y - αv1) = 0

If (x, y - αv1) = 0, then (v1, v2) is also 0. Therefore, α = (x, y)/||x||^2.

To obtain the unit orthogonal basis for the sub-space spanned by x and y, we simply normalize v1 and v2. The Matlab code for this is:

main.m
x_norm = norm(x);
y_norm = norm(y);
v1 = x / x_norm^2;
alpha = dot(x, y) / x_norm^2;
w2 = y - alpha * v1;
w2_norm = norm(w2);
v2 = w2 / w2_norm^2;

% Check if v1 and w2 are orthogonal
if dot(v1, w2) < eps
   disp('v1 and w2 are not orthogonal')
end

% Check if v1 and v2 are orthogonal and form a unit orthogonal basis
if dot(v1, v2) < eps
   disp('v1 and v2 are not orthogonal')
elseif abs(norm(v1) - 1) > eps || abs(norm(v2) - 1) > eps
   disp('v1 and/or v2 are not unit vectors')
else
   disp('v1 and v2 form a unit orthogonal basis')
end
542 chars
22 lines

gistlibby LogSnag