MATLAB Answers

0

How does Matlab divide two row vectors by each other to get a scalar?

Osama Tabbakh さんによって質問されました 2019 年 10 月 16 日
最新アクティビティ Star Strider
さんによって コメントされました 2019 年 10 月 17 日
Let's consider, A is a vector like shown:
A = [20 30 40];
and B is also a vector:
B = [5 10 20];
when you want to execute this operation:
C = B/A;
then you will get a scalar: 0.4137
if you want to check this answer by doing this:
C.*A
It should be got B again but you will get this vector instead:
ans =
8.2759 12.4138 16.5517
Could somebody explain what's going on?

  4 件のコメント

Adam
2019 年 10 月 16 日
doc mrdivide
explains that B/A is solving a set of linear equations x*A = B for x.
Clearly you can't expect to multiply A by any scalar and get B as the result. That is trivially obvious!
Stephen Cobeldick
2019 年 10 月 16 日
"It should be got B again"
Can you show us the system of equations for which this statement is true?
Osama Tabbakh 2019 年 10 月 16 日
I was just an example for understanding how calculate matlab this scalar 0.4137 and why it is scalar.

サインイン to comment.

製品


リリース

R2019b

1 件の回答

Star Strider
回答者: Star Strider
2019 年 10 月 16 日
 採用された回答

To expand slightly on that, ‘C’ is the least-squares estimate of the slope of with the y-intercept forced through the origin:
figure
plot(A,B,'p', A,C*A,'-r', [0 A(1)],C*[0 A(1)],':k')
axis([0 45 0 25])

  4 件のコメント

Star Strider
2019 年 10 月 17 日
As always, my pleasure.
Calculating the slope alone is straightforward (β is the slope parameter):
Set this equal to zero and solve to get:
If you want a more general solution, see the Wikipedia article on Linear least squares.
Osama Tabbakh 2019 年 10 月 17 日
Thanks!
Star Strider
2019 年 10 月 17 日
As always, my pleasure!

サインイン to comment.



Translated by