Random dot product tricks

12 ビュー (過去 30 日間)
Jesse
Jesse 2013 年 9 月 27 日
コメント済み: Jesse 2013 年 9 月 29 日
Greetings again,
I have two arrays:
x = [1.3, 5.6, 7.8, -6.5, 0.3]
y = [134.2, 8786.98, -22.4, 4553518.6, 0.0019]
Now, I know how to do the dot product
a=dot(x,y)
and the reverse (i.e, the first dot product has the summation from 1 to 5, but the reverse is 5 to 1),
so
xback = fliplr(x);
yback = fliplr(y);
b=dot(x,y)
but what about largest-to-smallest order dot produc? Is there anyway to organize that in MATLAB from the original arrays?
I didn't know if this was with the sort command.
Thanks!

採用された回答

Walter Roberson
Walter Roberson 2013 年 9 月 27 日
編集済み: Walter Roberson 2013 年 9 月 27 日
xy = x.*y;
dotxy = sum(sort(xy(xy>0), 'descend')) + sum(sort(xy(xy<0)));
  1 件のコメント
Jesse
Jesse 2013 年 9 月 29 日
Yes - that's what I was looking for. Very tight too!
Thanks Walter!

サインインしてコメントする。

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 27 日
編集済み: Azzi Abdelmalek 2013 年 9 月 27 日
If you sort a or b or both the result will be different.
Maybe you want to do other thing. Clarify what you want to achieve
% dot(a,b) is the same then sum(a.*b)
  3 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 27 日
No this is not clear, illustrate with a numeric example
Jan
Jan 2013 年 9 月 27 日
編集済み: Jan 2013 年 9 月 27 日
What is your purpose of creating the partial sums at first? Do you want to increase the accuracy of the result? Then better use FEX: XSum: XSum(a .* b).

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by