p8_17.m

来自「Advanced Engineering Mathematics using M」· M 代码 · 共 46 行

M
46
字号
% P8_17.M Fourier series of Square wave %% Plot the Fourier series of the function f(t) %   f(t)=1     0 < t < pi%   f(t)=-1   -pi < t <  0%clearT=2*pi		% Periodw0 = 2*pi/T	% Radian frequencyA=1		% AmplitudeK=(4*A)/pi;% Plot 5 terms of the seriest = -pi:.031:pi;	% Time points for plottingsizet=size(t);fn =(zeros(sizet));	% Fourier approximation at each typlt=zeros(sizet);		% For plot of f(t)% 5 termsfor n=1:5  fn= fn + K*(sin((2*n-1)*w0*t)/(2*n-1)); end					%for k=1:length(t)  if t(k) < 0    yplt(k)=-1;  else   yplt(k)=1;  end endclfsubplot(2,1,1),plot(t,fn,t,yplt,'--');xlabel('t')ylabel('f(t)')title('Fourier Series Approximation to Square Wave')legend(['N=',num2str(n)],'f(t)')% Add 5 more termsfor n=6:10  fn= fn + K*(sin((2*n-1)*w0*t)/(2*n-1)); end					subplot(2,1,2),plot(t,fn,t,yplt,'--');xlabel('t')ylabel('f(t)')legend(['N=',num2str(n)],'f(t)')%% Modify the script to allow an arbitrary number%  of components

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?