using symsum with a vector
조회 수: 6 (최근 30일)
이전 댓글 표시
I am trying to do a summation that cycles through a vector as its value of k (in my case m) increases. This isn't working for me as I cannot index the array with my value of m inside the symsum as this is not a symbolic representation. I do not fully know how to use symbolic variables in matlab so any help with how I could accomplish this would be helpful. I know I could do this with for loops but I want to figure out how ti use symbolic notation to accomplish this. I've attached the summations I am trying to recreate as well as my code.
Xm = [1 5 2 3 1]; %Original set
len = size(Xm,2);
Ak = zeros(1,len); %declaring sets
Bk = zeros(1,len); %declaring sets
Xk = zeros(1,len); %declaring sets
syms m;
for k = 0:len-1 %looping through each index and summing @ the current value
Ak(k+1) = symsum(Xm(m+1)*cos((2*pi*k*m)/len),m,0,len-1);
Bk(k+1) = symsum(Xm(m+1)*sin((2*pi*k*m)/len),m,0,len-1);
%Xk(k+1) = symsum(Xm(m+1)*exp((-1j*2*pi*k*m)/len),m,0,len-1); %An extra equation
end

댓글 수: 0
답변 (1개)
Walter Roberson
2022년 11월 15일
You cannot use symbolic notation for that purpose.
symsum() is primarily intended to attempt to find an indefinitely precise closed-form formula for the sum of the terms. For example, it can turn the taylor representation of sin() back into the sin() function. It is not intended to sum a number of definite terms.
What you need to do is calculate a vector (or array) of the definite terms ahead of time, and then sum() that over the appropriate dimension. The result will typically just be TERM1 + TERM2 + TERM3 + ... and so on, and will seldom be a formula. Do not for example expect to see fft(x) showing up as the result of sum() -- sum() makes no attempt to find an equivalent formula.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!