Advertisement
paulogp

Cos (v. 1.0.0)

Aug 7th, 2011
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.66 KB | None | 0 0
  1. function [ro, k, soma] = calculo_cos(x, erro)
  2. % paulogp
  3. % Algoritmo que, a partir de uma valor x lido em graus, permite o calculo
  4. % de y = cos(x)
  5. %
  6. % exemplo -> [ro, k, soma] = calculo(60, 10^-3)
  7.  
  8.     disp(' ');
  9.     disp('###################');
  10.     disp(' ');
  11.  
  12.     % formato de saida
  13.     format long
  14.    
  15.     erroTrunc = (erro / 2);
  16.     erroArr = (erro / 2);
  17.     k = 0;
  18.  
  19.     ro = (x^(2*k+2)) / factorial(2*k+2);
  20.  
  21.     while (ro >= erroTrunc)
  22.         ro = abs( (x^(2*k+2)) / factorial(2*k+2) );
  23.         k = k + 1;
  24.     end
  25.  
  26.     eap = (erroArr / k);
  27.     soma = 0;
  28.  
  29.     for i=0:k
  30.         soma = soma + ((-1)^i) * (x^(2*i)) / (factorial(2*i));
  31.     end
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement