Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Summation issue using loop

4 ビュー (過去 30 日間)
Ali aaa
Ali aaa 2019 年 10 月 18 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I am trying to implement this summation in matlab but i do not know how ?
thank u
  1 件のコメント
Robert U
Robert U 2019 年 10 月 18 日
What have you tried so far?

回答 (2 件)

Ali aaa
Ali aaa 2019 年 10 月 18 日
since n is just a number -1
for n=0:n-1
x(n+1) = ((x^2)(mN+i)
end

Robert U
Robert U 2019 年 10 月 20 日
Hi Ali aaa,
in your code parts are missing. Without knowing any constraints about the variables, I suggest the following solution:
  1. Define a (local) function to solve the summation formula
  2. check input validity
  3. Try to vectorize the calculation
function [Em] = sum_mNi(x,m,N)
validateattributes(x,{'numeric'},{'vector','nonempty'});
validateattributes(m,{'numeric'},{'scalar','nonempty'});
validateattributes(N,{'numeric'},{'scalar','nonempty'});
Em = 1/N * sum(cell2mat(arrayfun(@(ind) x.^2 .* (m*N + ind),0:N-1,'UniformOutput',false)'),1);
end
The solution might be wrong, depending on the input value types.
Kind regards,
Robert

この質問は閉じられています。

製品

Community Treasure Hunt

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

Start Hunting!

Translated by