Please help me with evaluating double sums

 採用された回答

Image Analyst
Image Analyst 2020 年 12 月 2 日

0 投票

You can do it with for loops, or with the meshgrid and sum functions:
x = 11 : 14
y = 2 : 5
% For loop way:
theSum = 0;
for i = 1 : 4
for j = 1 : 4
theSum = theSum + (x(i)^2 - 3 * y(j)^2 + x(i) * y(j)^3);
end
end
theSum
% Vectorized way using meshgrid:
[X, Y] = meshgrid(x, y);
theSum2 = sum(X(:) .^ 2 - 3 * Y(:) .^2 + X(:) .* Y(:) .^ 3)

1 件のコメント

Dominic Marquez
Dominic Marquez 2020 年 12 月 2 日
Thanks, it turns out that my confusion comes from doing rectangular rule with a low number of subintervals. Since my number was so far off the actual one, I thought I was doing it wrong. Turns out I spent those hours frustrating over nothing.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by