How can i solve this problem
Show older comments

I can't fill the answers Coefficients [c....] and %fill here for proper ... of C(k)
Answers (1)
David Hill
on 28 Oct 2021
Show me what you have tried for the C(k) equation above.
function C= FourierSeries(x,MaxK)
N=length(x);
n=0:N-1;
for k=1:2*MaxK+1
C(k)=%your equation look at sum() exp() .*
end
9 Comments
민호 김
on 28 Oct 2021
David Hill
on 28 Oct 2021
Show me your code for it and ask a specific question.
민호 김
on 28 Oct 2021
Edited: Walter Roberson
on 28 Oct 2021
David Hill
on 28 Oct 2021
What have you done? I am not going to write the computation of C(k) for you, but I can help you once you have made an effort and ask a specific question.
% Fill here for proper computation of C(k)
민호 김
on 28 Oct 2021
David Hill
on 28 Oct 2021
N=length(x);
for k = 1 : 2*MaxK+1
C(k)=0;%must initially set to zero
for n = 0 : N-1
c= x(n+1) * exp((-1j*2*pi*k*n)/N);%you need x(n+1) and not n (look at your equation). pi is a constant not phi. 1j or 1i is amaginary whereas i or j are variables.
C(k)=C(k)+c;%need to change the variable name of what you are adding
end
C(k)=C(k)/N;%once the sum is completed you need to do the final division by N.
end
Alturnatively, you would not need the inner for-loop if you use sum() and do element-wise operations.
N=length(x);
n=0:N-1;
for k=1:2*MaxK+1
C(k)=sum(x.*exp(-1j*2*pi*k*n/N))/N;
end
민호 김
on 28 Oct 2021
David Hill
on 28 Oct 2021
What should the coefficients be? The coefficients are complex, do you know if you are suppose to report only the magnitude?
Walter Roberson
on 28 Oct 2021
In MATLAB, [] is only used for building lists (and arrays) . [] is really the horzcat() or vertcat() function. The only place that [] is ever used for indexing in MATLAB is inside the Symbolic Engine, in the MuPAD programming language.
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!