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 中查找有关 Fourier Analysis and Filtering 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!