Symbolic summation: how to set this index?

1 回表示 (過去 30 日間)
John
John 2019 年 1 月 23 日
コメント済み: Walter Roberson 2019 年 1 月 25 日
I'm trying to write the following symbolic sum in matlab:
However, I can't define the function:
T=(a^(mod(j-3,n))+ a^(n-mod(j-3,n))+a^(mod(j-1-n,n)) + a^(n-mod(j-1-n,n)))*(a^(mod(j-1,n))+ a^(n-mod(j-1,n))+a^(mod(j+1-n,n)) + a^(n-mod(j+1-n,n)))
to compute
symsum(T,j,1,n)
Any help on how to make this calculation?
  8 件のコメント
madhan ravi
madhan ravi 2019 年 1 月 24 日
Have a look about symsum() , that maybe the one you are looking for.
John
John 2019 年 1 月 24 日
I know about symsum. The issue is that I haven't been able to define the function to be used as an input in symsum. Anyway, I edited the question to make that point clearer.

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

採用された回答

Walter Roberson
Walter Roberson 2019 年 1 月 25 日
symsum(), like the rest of MATLAB, evaluates the symbolic expression that is passed in as its first argument, before the function itself gets control. This is a problem with your formula because mod() with symbolic inputs is.. weird...
So... Don't.
Instead, construct vectors of powers:
NL = 1:n;
Nm3 = mod(NL-3,n);
Nm1 = mod(NL-1,n);
NNm3 = n - Nm3;
NNm1 = n - Nm1;
Nm1n = mod(NL-1-n, n);
and so on. Then
sum( (a.^Nm3 + a.^NNm3 + a.^Nm1n + a.^NNm1n) .* second_term )
I suggest that you only use symsum() when you are trying to find formula, such as symsum(1/2^x, 1, N) and expecting back the formula 1 - (1/2)^N .
When you have finite limits, it is almost always better to create a vector containing the individual terms, and sum() the vector.
If you were hoping that you could use symsum() to create an expression with generalized n so that you could reason with the formula, or fill in particular n values later, then you should probably give up all hope of that with symsum() or with symfun().
  2 件のコメント
John
John 2019 年 1 月 25 日
Must the value for n be set then? Leaving it as a symbolic integer, gives the error message "Unable to compute number of steps from 1 to n by 1."
Walter Roberson
Walter Roberson 2019 年 1 月 25 日
Yes, the value for n must be set for use with the colon operator. And mod() with symbolic expressions is nearly useless:
syms n j
mod(j-2, 5)
mod(j-2, n)
ans =
j + 3
Error using symengine
Invalid second argument.
Error in sym/privBinaryOp (line 1002)
Csym = mupadmex(op,args{1}.s, args{2}.s, varargin{:});
Error in sym/mod (line 18)
C = privBinaryOp(A, B, 'symobj::zipWithImplicitExpansion', 'symobj::modp');
You can try rewriting in terms of floor: mod(A,B) -> A - floor(A/B)*B

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by