inner product of any two vectors x and y in rn. that is, the inputs are x and y and n; the output is (x, y) = x t y. in matlab

To calculate the inner product of two vectors x and y in Rn, we need to take the transpose of x and multiply it with y.

In MATLAB, this can be simply done using the built-in function dot().

main.m
% Inputs
x = [1, 2, 3];
y = [4, 5, 6];

% Calculation
ip = dot(x, y);

% Output
disp(ip);
90 chars
10 lines

The output will be 32, which is the inner product of x and y.

Alternatively, we can use matrix multiplication to get the same result.

main.m
% Inputs
x = [1, 2, 3];
y = [4, 5, 6];

% Calculation
ip = x * y';

% Output
disp(ip);
87 chars
10 lines

Here, we have taken the transpose of y to make it a column vector, and then used matrix multiplication to get the inner product.

Again, the output will be 32.

gistlibby LogSnag