Advertisement
Guest User

test2

a guest
Apr 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. clear
  2. % Define a set of x values
  3. x=[0:0.02:2];
  4.  
  5. % x-values for the original function
  6. x1=[0:.1:1];
  7. x2=[1:.1:2];
  8.  
  9. % Number of terms in the sum
  10. numsum=30;
  11.  
  12. % Sum at each x to find the FS for f(x)
  13.  
  14. ser(1:length(x))=(7/6);
  15. for n=1:numsum
  16. 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);
  17. end
  18. y=ser;
  19.  
  20. % Compute the original function
  21. %
  22. y1=1*ones(length(x1),1);
  23. y2=-1+x2.^2;
  24.  
  25. %Plot the Fourier series and the original function over [0,2]
  26. %
  27. plot(x,y,x1,y1,'x',x2,y2,'x')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement