Advertisement
kaburen

TrygInt

May 22nd, 2019
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.55 KB | None | 0 0
  1. function[f]=InterTryg(Y)
  2. n=length(Y)-1;
  3. for i = 0 : n
  4.     X(i+1)=(2*i*pi)/(n+1);
  5. end
  6. if(mod(n,2)==0)
  7.     d = 0;
  8.     p = 0.5*n;
  9. else
  10.     d = 1;
  11.     p = 0.5*(n-1);
  12. end
  13. A=zeros(1,p+1);
  14. B=zeros(1,p+1);
  15. for i = 1 : p+1
  16.    
  17.     for j = 1: n+1
  18.        A(i)=A(i)+Y(j)*cos((i-1)*X(j));
  19.        B(i)=B(i)+Y(j)*sin((i-1)*X(j));
  20.     end
  21.     A(i) = A(i)*(2/(n+1));
  22.     B(i) = B(i)*(2/(n+1));    
  23. end
  24. syms x
  25. f = 0.5*A(1);
  26. for i = 1:p
  27.     f = f +((A(i+1)*cos(i*x) + B(i+1)*sin(i*x)));
  28. end
  29. f = f + 0.5*d*cos(p+1)*x;
  30. f = simplify(f);
  31. ezplot(f)
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement