Filter löschen
Filter löschen

Triple Summation in Matlab

4 Ansichten (letzte 30 Tage)
Summer
Summer am 29 Apr. 2019
Beantwortet: Steven Lord am 30 Apr. 2019
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.
triple summation.png
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 Kommentare
Steven Lord
Steven Lord am 29 Apr. 2019
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.]
Summer
Summer am 30 Apr. 2019
I'm using recent releases (i.e. 2019). How about going with the assumption of them being arrays first?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Steven Lord
Steven Lord am 30 Apr. 2019
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.

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by