Simulating Gibbs Phenomenon with MATLAB (Persian)
You can use the following link to find the script used in this presentation:
http://www.slideshare.net/Skhobahi/gibbsm
19. Final CodeFinal Code
n = 1000; % tedade noghate square waven = 1000; % tedade noghate square wave
t = linspace(-pi,pi,n); % tolide n noghte dar bazeye (-pi,pi)t = linspace(-pi,pi,n); % tolide n noghte dar bazeye (-pi,pi)
y = sign(t); % va tolide step wavey = sign(t); % va tolide step wave
M =30;M =30;
sum = zeros(1,length(t));sum = zeros(1,length(t));
for i = 1:2:Mfor i = 1:2:M
sum = sum + (pi/2.5)*(sin(i*t)/i);sum = sum + (pi/2.5)*(sin(i*t)/i);
endend
%Start Plotting%Start Plotting
plot(t,y,'LineWidth',1.2);plot(t,y,'LineWidth',1.2);
hold on;hold on;
plot(t,sum,'r','LineWidth',1.5); %'r' stands for the color redplot(t,sum,'r','LineWidth',1.5); %'r' stands for the color red
%Initializing the Figure Window%Initializing the Figure Window
axis([-2*pi 2*pi -1.5 1.5]); %modifing axis' limitsaxis([-2*pi 2*pi -1.5 1.5]); %modifing axis' limits
thetitle = ['Coefficient = ' num2str(M)];thetitle = ['Coefficient = ' num2str(M)];
title(thetitle);%set the tile of our figuretitle(thetitle);%set the tile of our figure