In: Advanced Math
Use the Gram-Schmidt process to transform the following vectors into an orthonormal basis of R4:
u1=?(0 2 1 0)?, u2=(?1 −1 0 0) ,u3=?(1 2 0 −1?), u4=?(1 0 0 1?)
can you do this in MATLAB with step by step on how to use the code
MATLAB Code:
close all
clear
clc
% Given vectors
u1 = [0 2 1 0];
u2 = [1 -1 0 0];
u3 = [1 2 0 -1];
u4 = [1 0 0 1];
% Gram-Schmidt Process
% v1 = u1
% v2 = u2 - projection of u2 onto v1
% v3 = u3 - projection of u3 onto v1 - projection of u3 onto
v2
% v4 = u4 - projection of u4 onto v1 - projection of u4 onto v2 -
projection of u4 onto v3
% and projection of u onto v = (<u, v>/<v, v>) *
v
% where <u, v> = inner product or dot product of u and
v
% Finally, normalize them to get the orthonormal set
v1 = u1;
v2 = u2 - sum(u2.*v1)/sum(v1.*v1) * v1;
v3 = u3 - sum(u3.*v1)/sum(v1.*v1) * v1 - sum(u3.*v2)/sum(v2.*v2) *
v2;
v4 = u4 - sum(u4.*v1)/sum(v1.*v1) * v1 - sum(u4.*v2)/sum(v2.*v2) *
v2 - sum(u4.*v3)/sum(v3.*v3) * v3;
v1 = v1/norm(v1);
v2 = v2/norm(v2);
v3 = v3/norm(v3);
v4 = v4/norm(v4);
fprintf('Orthonormal Set:\n')
fprintf('v1 = '), disp(v1)
fprintf('v2 = '), disp(v2)
fprintf('v3 = '), disp(v3)
fprintf('v4 = '), disp(v4)
Output: