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!