Está en la página 1de 2

# incluye < iostream >

# include < fstream >


# include < cmath >
utilizando namespace std ;

doble f ( doble x) {

devuelve el pecado ( pow (x, 2 )); // funcion


}

trapecio doble ( int n, double a, double b) {

doble h = (ba) / n;
doble _a = a;
integral doble = f (a) + f (b);
doble integralSum = 0 ;
para ( doble i = _a + h; i <b; i + = h) {
integralSum + = f (i);
}
return (integral + 2 * integralSum) * h / 2 ;
}

doble rombergHelper ( double * aproximationsLvl1, int k, int me) {


si (k == 1 ) {
volver aproximacionesLvl1 [yo];
}
else {
return ( pow ( 4 , k- 1 ) * rombergHelper (aproximationsLvl1, k- 1 , me + 1 ) -
rombergHelper (aproximadamente rtvl1 , k- 1 , me)) / ( pow ( 4 , k- 1 ) - 1 );
}
}

doble romberg ( double a, double b, int numberOfApprox) {

double initialApprox [numberOfApprox];


doble h = (ba) / numberOfApprox;
doble integral

para ( int i = 0 ; i <numberOfApprox; i ++) {


doble n;
cout << " Número de trapecios por aproximación " << i << " : " ;
cin >> n;
initialApprox [i] = trapecio (n, a, b);
}

integral = rombergHelper (initialApprox, numberOfApprox, 0 );


retorno integral
}

int main () {
doble integral, a, b;
int numberOfApprox;

cout << " a = " ;


cin >> a;
cout << " b = " ;
cin >> b;
cout << " Número de aproximaciones iniciales = " ;
cin >> númeroOfApprox;

integral = romberg (a, b, numberOfApprox);

cout << " Integral = " << integral << endl;

También podría gustarte