Triple Summation in Matlab
4 ビュー (過去 30 日間)
古いコメントを表示
I have the below triple summarion that I need to incorporate into a MATLAB code. Could you please help me with the code of such summation.

F is some factor that depends on a source i, T is a Penalty that depends on the distance for transporation from a source i to a place j, and a is an amount added from i to j in a time period p.
Thanks.
2 件のコメント
Steven Lord
2019 年 4 月 29 日
What release are you using? Certain techniques that may be useful here will only work in recent releases, so before suggesting them I want to check if you're using an older release.
What does size show for the variables F, a, and T? [I'm assuming they're arrays, not functions that you evaluate with the indices. If that's not a valid assumption, that information will be useful to know.]
回答 (1 件)
Steven Lord
2019 年 4 月 30 日
For the first term
if F is a column vector and a is a 3-dimensional array that have compatible sizes just multiply them using array multiplication (as opposed to matrix multiplication.)
F = [1; 2; 3]; % size [3 1] (or [3 1 1] or [3 1 1 1] or ...)
a = reshape(1:60, [3 4 5]); % size [3 4 5]
result = F.*a; % size [3 4 5]
Remember as stated on the first of the pages to which I linked, "Every array in MATLAB has trailing dimensions of size 1." Even though F and a have different numbers of dimensions, the implicit trailing dimensions of F mean that they are compatibly sized.
Now sum result over 'all' its dimensions to add together all the values in the result array. When I did this I got a result of 3700 for the example F and a arrays above.
thesum = sum(result, 'all')
If this is for a homework assignment that states you're not allowed to use sum, you can use for loops to iterate through the elements in F and the rows, columns, and pages of a.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!