I was doing some programming on Matlab and i stumbled upon this part in the code:
[1 1 1 1 1 1 1 1]/[ 1 3 4 7 9 11 13 15]
ans = 0.0939
I wanted to know how exactly did it compute this division
Thank you for your time,
I tried dividing element by element and i tried summing elementts of each vector and dividing it
The /
operator is an alias for mrdivide
, which has documentation.
x = B/A solves the system of linear equations x*A = B for x. The matrices A and B must contain the same number of columns. MATLAB® displays a warning message if A is badly scaled or nearly singular, but performs the calculation regardless.
- If A is a scalar, then B/A is equivalent to B./A.
- If A is a square n-by-n matrix and B is a matrix with n columns, then x = B/A is a solution to the equation x*A = B, if it exists.
- If A is a rectangular m-by-n matrix with m ~= n, and B is a matrix with n columns, then x = B/A returns a least-squares solution of the system of equations x*A = B.
Emphasis mine, for the case which you are showing, where A
is a rectangular m-by-n matrix (m=1, n=8) and B
is a matrix with n=8 columns.
So your result is the "least-squares solution of the system x*A=B
", where you have x=0.0939
.
You can visualise this as finding the minimum of
norm([1 1 1 1 1 1 1 1] - X*[ 1 3 4 7 9 11 13 15])
i.e.
x = 0:0.001:0.3;
y = arrayfun( @(X) norm([1 1 1 1 1 1 1 1] - X*[ 1 3 4 7 9 11 13 15]), x );
figure; plot( x, y )
(Note MATLAB is not doing this plot under the hood, this is purely a visualisation to convince yourself what the operation represents)