Coding a complicated summation.

2 ビュー (過去 30 日間)
rj
rj 2017 年 5 月 27 日
コメント済み: Jan 2017 年 5 月 28 日
Hello all,
I am very new to matlab and am struggling to code the following: I have the following matrices: 4 by 1
X = [x_1 x_2 x_3 x_4]', [u_1 u_2 u_3 u_4]'
Divide them into two groups:
[x_1 x_2], [u_1 u_2] and
[x_3 x_4], [u_3 u_4]
and I want the following sum:
[x_1 x_2]*[u_1 u_2]'[u_1 u_2]*[x_1 x_2]'+
[x_1 x_2]*[u_1 u_2]'[u_3 u_4]*[x_3 x_4]'+
[x_3 x_4]*[u_3 u_4]'[u_1 u_2]*[x_1 x_2]'+
[x_3 x_4]*[u_3 u_4]'[u_3 u_4]*[x_3 x_4]'
  • = matrix multiplication.
I know how to code if we are summing over x_iu_j for i from 1 to 4 and j = 1 to 4.. but dont know how to do this sum when you group the observations.. Upon grouping I only know how to code :
[x_1 x_2][u_1 u_2]'[u_1 u_2][x_1 x_2]'+[x_3 x_4][u_3 u_4]'[u_3 u_4][x_3 x_4]'.
Any suggestions would be much appreciated. Thank you.
  3 件のコメント
rj
rj 2017 年 5 月 27 日
I updated my question.. hope it is more clear now.. thank you for noticing...
Jan
Jan 2017 年 5 月 28 日
Sorry, it is still unclear:
[x_1 x_2]*[u_1 u_2]'[u_1 u_2]*[x_1 x_2]'
Please use proper Matlab syntax.

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

回答 (1 件)

Star Strider
Star Strider 2017 年 5 月 27 日
You seem to have coded what you want to do efficiently.
You only need to include multiplication operators (and possibly some others) to do the dot-products and other operations (see the documentation on Array vs. Matrix Operations (link)), then create your code as a function. See the documentation on Function Basics (link) if you are unfamiliar with them.
  3 件のコメント
Walter Roberson
Walter Roberson 2017 年 5 月 27 日
Would the matrices become 400 x 1 or 1600 x 1, or is it that you have 400 or 600 of those 4 x 1 matrices?
Star Strider
Star Strider 2017 年 5 月 27 日
My pleasure.
If you are operating on a small number of elements in your code each time to get the summations, it might be easiest to create a function from your code, then call it in a loop with the appropriate inputs (arguments). With a function, it would also be easier to be certain the code is doing what you want, before using it on a large data set.
Also, what operators go here?
[x_1 x_2][u_1 u_2]'[u_1 u_2][x_1 x_2]'
What result do you want?

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

カテゴリ

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