No BSD License  

Highlights from
Alternative Mathematics using MATLAB 7

image thumbnail

Alternative Mathematics using MATLAB 7

by

 

13 Mar 2003 (Updated )

Self-instructive text on undergraduate algebra, statistics, differential and integral calculus.

ex242.m
% ex242.m:  Plot of Fourier Series		
clear all
L=input('Period length=  (e.g. 6) ');		
T=-L/2: 0.01: L/2;  Y=0*T;		% First function for summing
for ni=0:20					% n not allowed as loop index
   n=ni;					
   c=(2/L)*quadL( @fcosl, -L/2, L/2, [ ], [ ], n, L);	% Integral for c(n)
   if n==0;  c= c/2;  end;
   s=(2/L)*quadL( @fsinl, -L/2, L/2, [ ], [ ], n, L);	% Integral for s(n)
						% Fourier approximation to f(x):
   Y=Y+ c*cos(2*pi* n*T/ L)+ s*sin(2*pi* n*T/ L);	
   figure(1),  plot(T,Y,'r',  T,funl(T),'b'),  xlabel('t'),  ylabel('funl'),   grid on
   pause(0.5)	
   if n>0					% Make coefficient vectors for plot
      N(n)=n;	 C(n)=c;  S(n)=s;	
   end
end
figure(2),  plot(N,C,'*', N,C,  N,S,'o', N,S),  grid on
   xlabel('n'),   ylabel('c (*), s (o)')
Cm=abs(C);  Sm=abs(S);
figure(3),  semilogy(N,Cm,'*', N,Cm, N,Sm,'o', N,Sm),  grid on
   xlabel('n'),  ylabel('magnitude of coefficients: c=*,  s=o')

Contact us