2D summation loop

1 次查看(过去 30 天)
John Allen
John Allen 2019-8-22
How do I create this in MATLAB?
formula.png
  2 个评论
James Tursa
James Tursa 2019-8-22
What have you done so far? What specific problems are you having with your code? Do you know how to write a for-loop, or use the sum( ) function, or use the diff( ) function, or use the .* operator?
John Allen
John Allen 2019-8-22
Yes, I know all of those, just never did it like this, so totally confused how to structure this one.

请先登录,再进行评论。

采纳的回答

James Tursa
James Tursa 2019-8-23
编辑:James Tursa 2019-8-23
Take the denominator for instance. Literally written out, this would be
denominator = 0;
for k=1:K
denominator = denominator + B(k,j)^2;
end
Or, assuming the first dimension of B is K, then you could use the sum( ) function:
denominator = sum(B(:,j).^2);
You can construct similar code for the numerator.
Probably best if you code everything up using for-loops just to get something running that works. Then you can simplify things with the sum( ) and diff( ) functions. It is possible to do the entire operation to construct ds without loops.
  4 个评论
John Allen
John Allen 2019-8-23
OK, thank you very much, I think I get it now, I marked answer as accepted.
Thanks again! :)
James Tursa
James Tursa 2019-8-23
If you have trouble, don't hesitate to post your current code and the problems you are having and we can still help you.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by