- 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.
When using matlab, you can actually divide a scalar by column vector and produce a result; how does Matlab execute this?
20 views (last 30 days)
Show older comments
I've been working on a solution to this and have gotten this far:
While matlab is looking for the greatest value to divide by, it is only looking for the first occurrence which is why it only prints a value once.
So you have a scalar: k divided by the column [a; b; c]. Matlab first checks if (a >= b) && (a >= c). If a is the largest value or equal to the other values, then it is used to divide and then its position (first) is used to index, and the rest of the values are 0. This is why when you divide 1 by [4; 4; 4], even though all the values are equal, it returns 0.25 0 0.
If the first condition is false, then matlab checks if b>=c. If b is larger than or equal to c, then it is used to divide and then its position (second) is used to index, and the rest of the values (first and third) are 0. So for example, if you divide 1 by [2; 4; 4], you will return 0 0.25 0.
If the first and second condition are false, then matlab knows that c is the greatest number and uses it to divide and uses its position as the index (so third). So for example, if you divide 1 by [2; 2; 4] you will return 0 0 .25.
This is obvious and logical but I'm skeptical if this is true. If it were true, how can you explain inf./[0;0;0] vs inf/[0;0;0]? The first works and the second gives a warning but proceeds and gives the answer 0 0 0. (The warning is "Warning: Rank deficient, rank = 0, tol = 0.000000e+00. "
0 Comments
Accepted Answer
Jan
on 7 Mar 2018
Edited: Jan
on 7 Mar 2018
The operation A/B is explained in the documentation: doc mrdivide. In your case A is a scalar and B a vector. This matches this case:
So you get a least squares solution, see. e.g. https://en.wikipedia.org/wiki/Linear_least_squares_(mathematics) .
0 Comments
More Answers (1)
James Tursa
on 7 Mar 2018
You are using two different operators, the ./ operator which is element-wise division, and the / operator which is matrix division (i.e., linear algebra). So you should not be comparing their results since they are two different operations.
The rules for the element-wise operator ./ are straightforward since it is just scalar division between two values.
The rules for matrix division depend on the sizes of the operands. Rather than repeat them here, you should read about it in the doc:
0 Comments
See Also
Categories
Find more on Arithmetic Operations 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!