Sum of a series containing table column data

조회 수: 5 (최근 30일)
Leo Tu
Leo Tu 2021년 7월 4일
답변: Leo Tu 2021년 7월 5일
I have a table, T, with one column of data of length 12054. I need to then make the following sum
SUM_[k=0 to t-1] 0.5^abs(k-5)*T(t-k)
lambda(t) = 1 + ---------------------------------------------------------------
SUM_[k=0 to t-1] 0.5^abs(k-5)
I have tried using symsum and defining the numerator and denominator seperately but I cannot seem to get it right. If anyone could help me with this it would be much appreciated.
Edit: Below is my attempt
syms k x;
% S1(t) is my attempt at defining the numerator
S1(t) = symsum(0.5^(abs(k-5)*T(t-k)),k,0,t-1);
Unrecognized function or variable 't'.
% Next is my attempt at defining the denominator
for t=0:12054
S2(t) = symsum(0.5^(abs(k-5)),k,0,t-1);
end
Array indices must be positive integers or logical values.
Error in sym/privsubsasgn (line 1151)
L_tilde2 =
builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
Error in sym/subsasgn (line 972)
C = privsubsasgn(L,R,inds{:});
Edit 2: Second attempt at defining the numerator
syms k x;
>> for t=1:12054
S1(t) = symsum(0.5^(abs(k-5)*T(t-k)),k,0,t-1);
end
Error using sym/subsindex (line 864)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments
must be symbolic variables, and function body must be sym expression.
  댓글 수: 2
Yongjian Feng
Yongjian Feng 2021년 7월 4일
It makes more sense if you post your solution here first, then we can help you to improve it.
Leo Tu
Leo Tu 2021년 7월 4일
Sorry @Yongjian Feng, I have edited the post.

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

채택된 답변

Leo Tu
Leo Tu 2021년 7월 5일
For anyone interested, I have found a solution.
V = flip(T,1)
syms k;
for t=1:12054
L(t) = 1+symsum(.5.^abs(k-5)*V(t),k,0,12054-t)./symsum(.5.^abs(k-5),k,0,12054-t);
end
lambda = double(L);
lambda = flip(lambda,2) % flipping back because we initially flipped T to get V.

추가 답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 7월 4일
What is the value of k? Just presuming k is taken from the number of elements in T, the calc can be done, e.g:
k=0:numel(T)-1;
L=1+sum(.5.^abs(k-5)*T(1:end-k))./sum(.5.^abs(k-5));
  댓글 수: 1
Leo Tu
Leo Tu 2021년 7월 4일
Hi there, k is the summation index from k = 0 to k = t-1, where t is in relation to T(t) for t=1:12054.
So the result lambda(t) would be a vector (I think) of length 12054.

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by