Peter Blomgren
San Diego State University
SDSU Logo
Matlab Learning Resources Status — Abandoned
main  |  code  |  video  ||  home
 
vectors
%
% Row and Column Vectors
% Inner (result: scalar) and Outer Product (result: matrix)
%

% Let x be the vector [1 2 3 4 5]
x = (1:5);
fprintf('x is a %d-by-%d object\n\n',size(x));

% Let y be a column vector, width random elements
y = randn(5,1);
fprintf('y is a %d-by-%d object\n\n',size(y));

% Inner product: row-vector times column-vector
XY = x*y;

fprintf('x*y is a %d-by-%d object\n\n',size(XY));
XY

% Outer product: column-vector times row-vector
YX = y*x;

fprintf('\ny*x is a %d-by-%d object\n\n',size(YX));
YX
x is a 1-by-5 object

y is a 5-by-1 object

x*y is a 1-by-1 object

XY =
   12.7259

y*x is a 5-by-5 object

YX =
   -0.3999   -0.7998   -1.1997   -1.5995   -1.9994
    0.6900    1.3800    2.0700    2.7600    3.4500
    0.8156    1.6312    2.4469    3.2625    4.0781
    0.7119    1.4238    2.1357    2.8476    3.5595
    1.2902    2.5805    3.8707    5.1610    6.4512
Copyright © 2024 Peter Blomgren.