-
Notifications
You must be signed in to change notification settings - Fork 0
/
meanProduct.m
30 lines (28 loc) · 913 Bytes
/
meanProduct.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function meanxy = meanProduct(x, y)
%
% Matt Werner ([email protected]) - June 25, 2021
%
% Calculate the mean element-wise product of two n-by-1 vectors.
%
% Inputs:
%
% x, y - Quantities whose mean product is desired to be
% calculated. Note that the mean product is calculated
% element-wise; as such, the dimensions of x and y must
% match.
% Size: n-by-1 (vector)
% Units: ? (SI)
%
% Outputs:
%
% meanxy - The mean product of the quantities x and y.
% Size: 1-by-1 (scalar)
% Units: ? (SI)
%
%% Checks
% Ensure x and y are of the same dimension
assert(all(size(x) == size(y)), "Dimensions must match.")
assert(size(x, 2) == 1, "Quantities must be column vectors")
%% Computation
% Calculate the mean product
meanxy = x'*y/numel(x);