How to do foward right division?
2 views (last 30 days)
Show older comments
I have an array of A (1x182) and B (1x182). When I use C=A/B; it gives one single number. How did Matlab get that single number?
I understand if I use ./ I will get C=(1x182).
1 Comment
Accepted Answer
Guillaume
on 25 May 2016
The / operator ( mrdivide) is particular to matlab. It solves a system of linear equations. In your particular case, it finds x such that x*B = A (note the reversal of the order of A and B) using the least square method, so it basically performs a linear fit between A and B with the added constraint that the line goes through the origin.
0 Comments
More Answers (2)
Star Strider
on 25 May 2016
As I did my best to explain in my Answer to your earlier Question How to find a the scale of two data?, the mrdivide function solves the matrix division problem in a least-squares sense.
You can get the same result by solving the least-squares equation:
S = sum((B - scale*A).^2) % Least Squares Equation
dS/dscale = -2*sum((B - scale*A)*A) % Take Derivative w.r.t. ‘scale’
dS/dscale = -2*sum((B.*A - scale*A.^2) % Distribute
dS/dscale = -2*sum(B.*A) - scale*sum(A.^2) % Simplify
sum(B.*A) = scale*sum(A.^2) % Set Derivative To Zero And Rearrange
scale = sum(B.*A) / sum(A.^2) % Solve For ‘scale’
NOTE: Do not run any other than the last line of that code! It describes an algebraic derivation of the least-squares estimator for ‘scale’, and will throw a number of errors if you try to run it.
So using the vectors in your previous Question:
A=[0.46,-0.51,1.02,-1.02,1.55,-1.55,2.06,-2.06,2.02];
B=[0.09,-0.13,0.32,-0.29,0.38,-0.41,0.48,-0.56,-0.36];
scale_rdivide = B/A
scale_leastsquares = sum(A.*B) / sum(A.^2)
scale_rdivide =
169.1133e-003
scale_leastsquares =
169.1133e-003
0 Comments
See Also
Categories
Find more on Linear Algebra 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!