Modify the attached code to implement vector projection.
4 views (last 30 days)
Show older comments
attached code :
function y = proj(x, V)
% x (nx1): input vector
% V (nxk): matrix, whose column vectors are supposed to be orthonormal
% y (nx1): projection of x onto the span of the column vectors of V
x = [1; 2; 3];
V = [[1; 0; 0] [0; 1/sqrt(2); 1/sqrt(2)]];
y = zeros(size(x));
Question : How can i calculate this code? (y = proj(x, V))
I can't solve this problem... Isn't it using the dot product?
0 Comments
Answers (1)
Aditya
on 22 Feb 2024
Hi jaeuk,
I understand that you are looking to implement vector projection in MATLAB. The key is to use the dot product to project the vector x onto each orthonormal basis vector in V and sum these projections.
The modified code is as follows:
function y = proj(x, V)
% x (nx1): input vector
% V (nxk): matrix, whose column vectors are supposed to be orthonormal
% y (nx1): projection of x onto the span of the column vectors of V
% Initialize y as a zero vector of the same size as x
y = zeros(size(x));
% Loop over each column vector in V
for k = 1:size(V, 2)
% Calculate the projection of x onto the k-th column vector of V
y = y + (dot(x, V(:,k)) * V(:,k));
end
To visualize this in a 3D space (for 3x1 vectors) for the attached example, you can use MATLAB's “plot3” function. However, for dimensions higher than three, a direct visual representation is not possible with “plot3”. In such cases, you may need to reduce the dimensionality for visualization or use alternative methods to represent high-dimensional data.
Hope this helps!
0 Comments
See Also
Categories
Find more on Software Development Tools in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!