Extra Questions

4
MATLAB CODE f(x)=|sin(x)| clc; clear all;close all close all; x=[-pi:0.1:pi]; f=abs(sin(x)); a0=2/pi; n=[2 4]; for i=1:length(x) f2(i)=2/pi*sum((1+(-1).^n)./(1-n.^2).*cos(x(i).*n)); const(i)=a0; end f2=f2+a0; n=[2 4 6]; for i=1:length(x) f3(i)=2/pi*sum((1+(-1).^n)./(1-n.^2).*cos(x(i).*n)); end f3=f3+a0; hold on plot(x,f,'g-') plot(x,const,'r') plot(x,f2,'b.-') plot(x,f3,'k--') axis([min(x) max(x) min(f) max(f)]) legend('Original Function','Constant Approx','Approx upto 2 NZ terms',... 'Approx upto 3 NZ terms')

description

mm

Transcript of Extra Questions

MATLAB CODE f(x)=|sin(x)|clc; clear all;close allclose all;x=[-pi:0.1:pi];f=abs(sin(x)); a0=2/pi; n=[2 4];for i=1:length(x) f2(i)=2/pi*sum((1+(-1).^n)./(1-n.^2).*cos(x(i).*n)); const(i)=a0;endf2=f2+a0; n=[2 4 6];for i=1:length(x) f3(i)=2/pi*sum((1+(-1).^n)./(1-n.^2).*cos(x(i).*n));endf3=f3+a0; hold onplot(x,f,'g-')plot(x,const,'r')plot(x,f2,'b.-')plot(x,f3,'k--')axis([min(x) max(x) min(f) max(f)]) legend('Original Function','Constant Approx','Approx upto 2 NZ terms',... 'Approx upto 3 NZ terms')

MATLAB CODE f(x)=|x|%%%%% EXAMPLE 8.2 of book %%%%%%% GRAPH is not exactly followed here clc; clear all;close allclose all;x=[-pi:0.1:pi];f=abs(x); a0=pi/2; n=[1 3];for i=1:length(x) f2(i)=2/pi*sum((-1+(-1).^n)./(n.^2).*cos(x(i).*n)); const(i)=a0;endf2=f2+a0; n=[1 3 5];for i=1:length(x)f3(i)=2/pi*sum((-1+(-1).^n)./(n.^2).*cos(x(i).*n));endf3=f3+a0; hold onplot(x,f,'g-')plot(x,const,'r')plot(x,f2,'b.-')plot(x,f3,'k--')axis([min(x) max(x) min(f) max(f)])legend('Original Function','Constant Approx','Approx upto 2 NZ terms',... 'Approx upto 3 NZ terms')

MATLAB CODE f(x) =x4

% GRAPH of x^4% an= Sum[((8*(-1)^n)(-6+n^2 Pi^2)/(n^4))Cos[nx]% bn =0 a0=pi^4/5;

clc; clear all;close allclose all;x=[-pi:0.1:pi];f=x.^4; a0=pi^4/5; n=[1 3];for i=1:length(x) f2(i)=8*sum(((-1).^n).*(-6+n.^2*pi^2)./(n.^4).*cos(x(i).*n)); const(i)=a0;endf2=f2+a0; n=[1 3 5];for i=1:length(x) f3(i)=8*sum(((-1).^n).*(-6+n.^2*pi^2)./(n.^4).*cos(x(i).*n));endf3=f3+a0; hold onplot(x,f,'g-')plot(x,const,'r')plot(x,f2,'b.-')plot(x,f3,'k--')axis([min(x) max(x) -30 max(f)])legend('Original Function','Constant Approx','Approx upto 2 NZ terms',... 'Approx upto 3 NZ terms')