Advertisement
xlujiax

asda

Sep 16th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.86 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. #include <iostream>
  8. #include <iomanip>
  9.  
  10. /* RCS*/
  11.  
  12. using namespace std;
  13.  
  14.  
  15. double potencia_auxiliar(double base, int exp){
  16.     double pot;
  17.     pot = 1;
  18.     for (int i = 1; i <= exp ; i++)
  19.         pot = pot * base;
  20.     return pot;
  21. }
  22.  
  23. double sen(double angulo,double precision){
  24.     double rad,serie; //rad = radianes
  25.     int  i,n;
  26.     double term,term_ant; //manejare el termino actual y anterior calculado
  27.     double PRECISION2;
  28.    
  29.    
  30.     PRECISION2 = 1 / potencia_auxiliar(precision + 1,10);
  31.     rad = angulo * 3.1416 /180;
  32.     term_ant = 0;
  33.     term = rad;
  34.     serie = rad;
  35.    
  36.    
  37.     n = 1;
  38.     i = 3;
  39.     while((term - term_ant) > PRECISION2){
  40.        
  41.         term_ant = term;
  42.         term *= rad*rad/(i *(i-1));
  43.        
  44.         if( ( n%2) != 0) serie = serie - term;
  45.         else serie = serie + term;
  46.        
  47.         n += 1;
  48.         i += 2;
  49.     }
  50.    
  51.     return serie;
  52. }
  53.  
  54. double cos(double angulo,double precision){
  55.     double rad,serie;
  56.     int i, n;
  57.    
  58.     double term, term_ant;
  59.     double PRECISION2 ;
  60.         PRECISION2 = 1 / potencia_auxiliar(precision + 1,10);
  61.         rad = angulo * 3.1416 /180;
  62.         term_ant = 0;
  63.         term = 1;
  64.         serie = 1;
  65.      
  66.         i = 2;
  67.         n = 1; //Indice para cada iteracion y ver si se suma o resta
  68.        
  69.         while((term - term_ant) >PRECISION2){
  70.          
  71.              term_ant = term;
  72.              term *= rad*rad/(i *(i-1));
  73.        
  74.              if( ( n%2) != 0) serie = serie - term;
  75.               else serie = serie + term;
  76.        
  77.              n += 1;
  78.              i += 2;
  79.         }
  80.        
  81.         return serie;
  82.    
  83. }
  84.  
  85.  
  86. double exp(double x, double precision){
  87.    
  88.     double serie;
  89.     double term,term_ant;
  90.     double PRECISION2;
  91.      
  92.     int i,n;
  93.    
  94.     PRECISION2 = 1 / potencia_auxiliar(precision + 1,10);
  95.    
  96.     term_ant = 0;
  97.     term = 1;
  98.     serie = 1;
  99.    
  100.     i = 1;
  101.        
  102.     while(term - term_ant > PRECISION2){
  103.        
  104.         term_ant = term;
  105.         term = term * x/ i ;
  106.         i += 1;
  107.         serie = serie + term;
  108.        
  109.     }
  110.    
  111.     return serie;
  112. }
  113.  
  114. double ln(double x,double precision){
  115.     double serie;
  116.     double term,term_ant;
  117.     double PRECISION2;
  118.      
  119.     int i,n;
  120.    
  121.     PRECISION2 = 1 / potencia_auxiliar(precision + 1,10);
  122.    
  123.     term_ant = 0;
  124.     term =  (x- 1)/x ;
  125.     serie = term;
  126.    
  127.     i = 2;
  128.        
  129.     while(term - term_ant > PRECISION2){
  130.        
  131.         term_ant = term;
  132.         term  *=  (x-1)/x;
  133.         term = term / i ;
  134.        
  135.         serie = serie + term;
  136.         i += 1;
  137.         term;
  138.     }
  139.    
  140.     return serie;
  141. }
  142.  
  143. double pot(double x, double y, double precision ){
  144.      double serie;
  145.     double term,term_ant;
  146.     double PRECISION2;
  147.      
  148.     int i,n;
  149.    
  150.     PRECISION2 = 1 / potencia_auxiliar(precision + 1,10);
  151.    
  152.     term_ant = 0;
  153.     term = y*ln(x,precision);
  154.     serie = 1 + term;
  155.    
  156.     i = 1;
  157.        
  158.     while(term - term_ant > PRECISION2){
  159.        
  160.         term_ant = term;
  161.         term  =  term* y*ln(x,precision) / (i *(i+1)) ;
  162.        
  163.        
  164.         serie = serie + term;
  165.         i += 1;
  166.        
  167.     }
  168.    
  169.     return serie;
  170. }
  171. double senh(double x, double precision){
  172.     double serie;
  173.     double term,term_ant;
  174.     double PRECISION2;
  175.      
  176.     int i,n;
  177.    
  178.     PRECISION2 = 1 / potencia_auxiliar(precision + 1,10);
  179.    
  180.     term_ant = 0;
  181.     term = x;
  182.     serie = x;
  183.    
  184.     i = 3;
  185.        
  186.     while(term - term_ant > PRECISION2){
  187.        
  188.         term_ant = term;
  189.         term *= x * x/ (i * (i-1)) ;
  190.         i += 2;
  191.         serie = serie + term;
  192.        
  193.     }
  194.    
  195.     return serie;
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement