Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- #include <iostream>
- #include <iomanip>
- /* RCS*/
- using namespace std;
- double potencia_auxiliar(double base, int exp){
- double pot;
- pot = 1;
- for (int i = 1; i <= exp ; i++)
- pot = pot * base;
- return pot;
- }
- double sen(double angulo,double precision){
- double rad,serie; //rad = radianes
- int i,n;
- double term,term_ant; //manejare el termino actual y anterior calculado
- double PRECISION2;
- PRECISION2 = 1 / potencia_auxiliar(precision + 1,10);
- rad = angulo * 3.1416 /180;
- term_ant = 0;
- term = rad;
- serie = rad;
- n = 1;
- i = 3;
- while((term - term_ant) > PRECISION2){
- term_ant = term;
- term *= rad*rad/(i *(i-1));
- if( ( n%2) != 0) serie = serie - term;
- else serie = serie + term;
- n += 1;
- i += 2;
- }
- return serie;
- }
- double cos(double angulo,double precision){
- double rad,serie;
- int i, n;
- double term, term_ant;
- double PRECISION2 ;
- PRECISION2 = 1 / potencia_auxiliar(precision + 1,10);
- rad = angulo * 3.1416 /180;
- term_ant = 0;
- term = 1;
- serie = 1;
- i = 2;
- n = 1; //Indice para cada iteracion y ver si se suma o resta
- while((term - term_ant) >PRECISION2){
- term_ant = term;
- term *= rad*rad/(i *(i-1));
- if( ( n%2) != 0) serie = serie - term;
- else serie = serie + term;
- n += 1;
- i += 2;
- }
- return serie;
- }
- double exp(double x, double precision){
- double serie;
- double term,term_ant;
- double PRECISION2;
- int i,n;
- PRECISION2 = 1 / potencia_auxiliar(precision + 1,10);
- term_ant = 0;
- term = 1;
- serie = 1;
- i = 1;
- while(term - term_ant > PRECISION2){
- term_ant = term;
- term = term * x/ i ;
- i += 1;
- serie = serie + term;
- }
- return serie;
- }
- double ln(double x,double precision){
- double serie;
- double term,term_ant;
- double PRECISION2;
- int i,n;
- PRECISION2 = 1 / potencia_auxiliar(precision + 1,10);
- term_ant = 0;
- term = (x- 1)/x ;
- serie = term;
- i = 2;
- while(term - term_ant > PRECISION2){
- term_ant = term;
- term *= (x-1)/x;
- term = term / i ;
- serie = serie + term;
- i += 1;
- term;
- }
- return serie;
- }
- double pot(double x, double y, double precision ){
- double serie;
- double term,term_ant;
- double PRECISION2;
- int i,n;
- PRECISION2 = 1 / potencia_auxiliar(precision + 1,10);
- term_ant = 0;
- term = y*ln(x,precision);
- serie = 1 + term;
- i = 1;
- while(term - term_ant > PRECISION2){
- term_ant = term;
- term = term* y*ln(x,precision) / (i *(i+1)) ;
- serie = serie + term;
- i += 1;
- }
- return serie;
- }
- double senh(double x, double precision){
- double serie;
- double term,term_ant;
- double PRECISION2;
- int i,n;
- PRECISION2 = 1 / potencia_auxiliar(precision + 1,10);
- term_ant = 0;
- term = x;
- serie = x;
- i = 3;
- while(term - term_ant > PRECISION2){
- term_ant = term;
- term *= x * x/ (i * (i-1)) ;
- i += 2;
- serie = serie + term;
- }
- return serie;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement