Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear
- % Define a set of x values
- x=[0:0.02:2];
- % x-values for the original function
- x1=[0:.1:1];
- x2=[1:.1:2];
- % Number of terms in the sum
- numsum=30;
- % Sum at each x to find the FS for f(x)
- ser(1:length(x))=(7/6);
- for n=1:numsum
- ser=ser+((x.^2 - 1)*(sin(2*pi*n) - sin(pi*n)))/(pi*n) + (sin(pi*n)/(pi*n))*cos(n*pi.*x) + ((x.^2 - 1)*(cos(pi*n) - cos(2*pi*n)))/(pi*n) + ((1 - cos(pi*n))/(pi*n))*sin(n*pi.*x);
- end
- y=ser;
- % Compute the original function
- %
- y1=1*ones(length(x1),1);
- y2=-1+x2.^2;
- %Plot the Fourier series and the original function over [0,2]
- %
- plot(x,y,x1,y1,'x',x2,y2,'x')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement