BORUTO-121

SIN_function_taylor_series(15)

Mar 5th, 2022 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.52 KB | None | 0 0
  1. function[y]=SIN(x)
  2. %%First step is to bring x between -2pi and 2pi
  3.  
  4. x=x-2*pi*fix((x/(2*pi)));
  5.  
  6. %%Second step is to bring x between -pi and ppi
  7. if(x<-pi)
  8.     x=x+2*pi;
  9. elseif(x>pi)
  10.     x=x-2*pi;
  11. end
  12.  
  13.     factorijel=1.;
  14.     predznak=1;
  15.     accX=1.;
  16.     y=0.;
  17.     N=50;
  18.     for i=1:N
  19.         factorijel=factorijel*i;
  20.         accX=accX*x;
  21.         if(mod(i,2)~=0)
  22.             y=y+accX*predznak/double(factorijel);
  23.             predznak=predznak*(-1);
  24.         end
  25.     end
  26.    y=round(y*10000)/10000.;
  27. end
  28.  
  29.  
  30.  
Add Comment
Please, Sign In to add comment