No hand soving at all Please only do them as MATLABWOLFRAMs
No hand soving at all! Please only do them as MATLAB/WOLFRAM\'s MATHMATICA CODE/SCRIPT. NO SELF CALCULATIONS
MATLAB/WOLFRAM\'s MATHMATICA CODE/SCRIPT ONLY
MATLAB/WOLFRAM\'s MATHMATICA CODE/SCRIPT ONLY PLEASE
Solution
function fn=f(x)
 if x<0 && x>-50
     fn=x+50;
 elseif x>0 && x<50
     fn=x-50;
 else
     fn=0;
 end
 end
function cs=cs(n)
 T=100;
 if n~=0
 fun=@(t)f(t).*cos((2.*pi.*n.*t)./T);
 cs=integral(fun,-50,50);
 cs=(2./T).*cs;
 else
     fun=@(t) f(t);
     cs=integral(fun,-50,50);
     cs=cs./T;
 end
 end
function sn=sn(n)
 T=100;
 fun=@(t) f(t).*sin((2.*pi.*n.*t)./T);
 sn=integral(fun,-50,50);
 sn=(2./T).*sn;
 end
T=100;
 disp(\'first five cos terms\');
 for m=0:4
     cs(m);
 end
 disp(\'first five sin terms\');
 for n=1:5
     sn(n)
 end
 A0=cs(0);
 N=10;
 A=zeros(1,N);
 B=A;
 for k=1:N
     A(k)=cs(k);
     B(k)=sn(k);
 end
 t=-50:0.1:50;
     fn_orginal=f(t);
     fun_trn=zeros(1,size(t));
 for n=1:N
 fun_trn=fun_trn+A(k).*cos((2.*pi.*n.*t)./T)+B(k).*sin((2.*pi.*n.*t)./T);
  end
 fun_trn=fun_trn+A0;
 plot(t,fun_trn)


