Where is the problem with my code. it never ends !!
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Geoff Hayes
am 18 Mai 2018
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 Kommentare
Siehe auch
Kategorien
Mehr zu Number Theory finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!