필터 지우기
필터 지우기

Triple Summation in Matlab

조회 수: 2 (최근 30일)
Summer
Summer 2019년 4월 29일
답변: Steven Lord 2019년 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.
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
Steven Lord
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.]
Summer
Summer 2019년 4월 30일
I'm using recent releases (i.e. 2019). How about going with the assumption of them being arrays first?

댓글을 달려면 로그인하십시오.

답변 (1개)

Steven Lord
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.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by