Where is the problem with my code. it never ends !!
조회 수: 1 (최근 30일)
이전 댓글 표시
What is the problem with the following code?
It calculates the exponential coefficients fo fourier series of periodic function f(t).
when I run it the compilation never ends !! and I must close matlab and run it again.
function [an]=fc(f,T)
syms t n
n=-20:1:20;
an=(1/T)*int(f*exp(-1i*n*2*pi*t/T),t,0,T);
end
syms t n
f=rectangularPulse(t/4)*(abs(t)-1);
%f=rectangularPulse(t);
% f=sin(t);
Y=fc(f,20);
subplot(211)
stem(-20:1:20,abs(Y));
ylabel('|an|')
grid;
subplot(212)
stem(-20:1:20,angle(Y));
ylabel('<an')
grid;
댓글 수: 0
답변 (1개)
Geoff Hayes
2018년 5월 18일
geometry - your function appears to be recursive
function [an]=fc(f,T)
syms t n
n=-20:1:20;
an=(1/T)*int(f*exp(-1i*n*2*pi*t/T),t,0,T);
end
syms t n
f=rectangularPulse(t/4)*(abs(t)-1);
%f=rectangularPulse(t);
% f=sin(t);
Y=fc(f,20); % <------------------
So it continually calls itself and without a stopping condition, it will call itself forever (!).
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Number Theory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!