iogha10 de Junio del 2006
PreguntaHola, alguien me podria ayudar a hacer un programa en c++ que calcula las integrales mediante la regla del trpecio simple y multiple??
Encontre este en internet, pero la funcion esta predeterminda, se los agradeceria mucho
#include <math.h>
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
float funcion(float);
float trapecio(float, float);
float trapecio_extendida(float, float, int);
void main(void);
float funcion(float x)
{
return pow(x,2)/2+3*x+2;
}
float trapecio(float a, float b)
{
return (b-a)*(funcion(a)+funcion(b))/2;
}
float trapecio_extendida(float a, float b, int n)
{
float h=(b-a)/n;
float sumatoria=0;
int j;
for (j=1;j<=n-1;j++)
sumatoria=sumatoria+funcion(a+j*h);
return (h/2)*(funcion(a)+2*sumatoria+funcion(b));
}
void main()
{
printf("\nResultado trapecio--> %f",trapecio(1,5));
printf("\nResultado trapecio extendida--> %f",trapecio_extendida(1,5,8));
scanf("\n");
}
Encontre este en internet, pero la funcion esta predeterminda, se los agradeceria mucho
#include <math.h>
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
float funcion(float);
float trapecio(float, float);
float trapecio_extendida(float, float, int);
void main(void);
float funcion(float x)
{
return pow(x,2)/2+3*x+2;
}
float trapecio(float a, float b)
{
return (b-a)*(funcion(a)+funcion(b))/2;
}
float trapecio_extendida(float a, float b, int n)
{
float h=(b-a)/n;
float sumatoria=0;
int j;
for (j=1;j<=n-1;j++)
sumatoria=sumatoria+funcion(a+j*h);
return (h/2)*(funcion(a)+2*sumatoria+funcion(b));
}
void main()
{
printf("\nResultado trapecio--> %f",trapecio(1,5));
printf("\nResultado trapecio extendida--> %f",trapecio_extendida(1,5,8));
scanf("\n");
}
