Sum of a series containing table column data

5 visualizaciones (últimos 30 días)
Leo Tu
Leo Tu el 4 de Jul. de 2021
Respondida: Leo Tu el 5 de Jul. de 2021
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 comentarios
Yongjian Feng
Yongjian Feng el 4 de Jul. de 2021
It makes more sense if you post your solution here first, then we can help you to improve it.
Leo Tu
Leo Tu el 4 de Jul. de 2021
Sorry @Yongjian Feng, I have edited the post.

Iniciar sesión para comentar.

Respuesta aceptada

Leo Tu
Leo Tu el 5 de Jul. de 2021
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.

Más respuestas (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 4 de Jul. de 2021
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 comentario
Leo Tu
Leo Tu el 4 de Jul. de 2021
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by