Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

//Metodo #include #include #include

de simpson ax2 + bx + c <stdio.h> <stdlib.h> <math.h>

float f(float x) { float y; //y = x * x * x - 2 * x * x + 7 * x - 5; y=cos((3.14159265358979323846/2)*cos(x))/sin(x); return y; } float Integra(float a , float b, int n) { //calculando diferencial x float dx,suma4x,suma2x,prefactor,postfactor,suma_total,total; int i=1; dx = (b - a) / n; //calculando primera parte de la integral suma4x = suma2x = 0; prefactor = (( b - a ) / ( 3 * n ) ); //calculando segunda partede la integral for(i=2;i<n;i+=2) { suma4x = suma4x + 4.0 * f(a + (i-1) * dx); suma2x = suma2x + 2.0 * f(a + i * dx); }//falta sumar el ltimo, penultimo y primer termino suma2x = suma2x + 4 * f( a + (n-1) * dx); termino suma_total = f(a) + suma4x + suma2x + f(b); ultimo termino postfactor = suma_total; total = prefactor * postfactor; return total; } int main() { system("cls"); float integra=Integra(0.001,3.1415846,100000); printf("%f",integra); system("pause"); } // --> Penultimo // --> Primer y

You might also like