#include <conio.h> #include <stdio.h> #include <math.h>
int opcion,j,pmx; long double error,errcal; long double a,b,c,d,Int_C,Int_T; long double Integral_doble_Teorica(int opcion,long double a,long double b); long double Integral_doble(long double c,long double d,long double error); long double simpson(long double a,long double b,int opcion,long double Y,long double error); long double f(int z,long double x,long double y);
void main() {
printf("\n\n Presione cualquier tecla para continuar "); getch(); do { do { opcion = 0; clrscr();
//=========================================================================================== // Opcion de Funciones //=========================================================================================== printf(" MENU DE FUNCIONES\n"); printf("\n==========================================================================="); printf("\n 1) f(x,y) = e(x) * e(y)"); printf("\n 2) f(x,y) = sin x * cos y"); printf("\n 3) f(x,y) = (2x)/y"); printf("\n 4) f(x,y) = e(xy)* x(2) ") ; printf("\n 5) f(x,y) = e(xy)* sin 2(xy) "); printf("\n 6) f(x,y) = (x*y)/(x+y)"); printf("\n 7) f(x,y) = ln(x+y)"); printf("\n 8) Para salir"); printf("\n==========================================================================="); printf("\n\n\n ELIJA LA FUNCION PARA CALCULAR EL VOLUMEN: "); scanf("%d",&opcion); clrscr(); } while(opcion<1 || opcion>8); if(opcion==8) return; ////////////////////////////////////////////////////////////////////////////// // Eleccion del int= clrscr(); printf("\n==========================================================================="); printf("\n INGRESE EL INTERVALO [A,B]"); printf("\n==========================================================================="); printf("\n\n A= "); scanf("%Lf",&a); printf("\n B= "); scanf("%Lf",&b); printf("\n\n C= "); scanf("%Lf",&c); printf("\n D= "); scanf("%Lf",&d); printf("\n\ncantidad de ciclos maximos pmx ="); scanf("%d",&pmx);
////////////////////////////////////////////////////////////////////////////// ////////////////////////// Eleccion del error /////////////////////////////// //////////////////////////////////////////////////////////////////////////////
clrscr(); printf("\n===========================================================================\n"); printf("\n ELIJA EL ERROR A UTILIZAR:"); printf("\n===========================================================================\n"); printf("\n\n SU ERROR ES DE: "); scanf("%Lf",&error);
// Resultados del Programa Int_T=Integral_doble_Teorica(opcion,a,b); Int_C=Integral_doble(c,d,error); errcal = fabsl(Int_C - Int_T); clrscr(); printf("\n====================================================================\n"); printf(" RESULTADOS DEL PROGRAMA"); printf("\n====================================================================\n"); if(opcion==1)printf("\n %lf LA FUNCION ELEGIDA ES f(x,y) = e(x) * e(y)\n",exp(1)); if(opcion==2)printf("\n LA FUNCION ELEGIDA ES f(x,y) = sin x * cos y\n"); if(opcion==3)printf("\n LA FUNCION ELEGIDA ES f(x,y) = (2x)/y\n"); if(opcion==4)printf("\n LA FUNCION ELEGIDA ES f(x,y) = e(xy)* x^2"); if(opcion==5)printf("\n LA FUNCION ELEGIDA ES f(x,y) = e(xy)* sin 2(xy)\n"); if(opcion==6)printf("\n LA FUNCION ELEGIDA ES f(x,y) = (x*y)/(x+y)\n"); if(opcion==7)printf("\n LA FUNCION ELEGIDA ES f(x,y) = ln(x+y)\n");
printf("\n El valor de a elegido es____________________________ [%Lf]",a); printf("\n El valor de b elegido es_____________________________ [%Lf]",b); printf("\n El valor de c elegido es_____________________________ [%Lf]",c); printf("\n El valor de d elegido es_____________________________ [%Lf]",d); printf("\n Error admitido______________________________________ %Lf",error); printf("\n Integral Doble Calculada____________________________ %Lf",Int_C); printf("\n Integral Doble Teorica______________________________ %Lf",Int_T); printf("\n El error calculado es de____________________________ %Lf",errcal); printf("\n==========================================================================\n"); printf("\n\n Para continuar presione cualquier tecla"); getche(); } while(opcion!=13); }
long double Integral_doble_Teorica(int opcion,long double a,long double b) { switch(opcion) { case 1:Int_T = (exp(b)-exp(a))*(exp(d)-exp(c)); break; case 2:Int_T = (cos(a)-cos(b))*(sin(d)-sin(c)); break; case 3:Int_T = (b*b - a*a)*(log(d)-log(c)); break; case 4:Int_T = 0;break; case 5:Int_T = 0;break; case 6:Int_T = 0;break; } return(Int_T); }
////////////////////////////////////////////////////////////////// //FUNCION QUE CALCULA EL AREA POR EL METODO DE LA INTEGRAL DOBLE// //////////////////////////////////////////////////////////////////
long double Integral_doble(long double c,long double d,long double error) {
int n,i,pasos; long double h,Y,Vol1,Vol2,Int[20];
pasos = 1; n = 4; h = fabsl(c-d)/n; for(i=0;i<=n;++i) { Y = c+i*h; Int[i] = simpson(a,b,opcion,Y,error); } Vol1 = (h/3)*(Int[0] + Int[4] + 4*(Int[1]+Int[3]) + 2* Int[2]); otro: n = n + 2; h = fabsl(c-d)/ n; for(i=0;i<=n;++i) { Y = c + i*h; Int[i] = simpson(a,b,opcion,Y,error); } Vol2 = Int[0] + Int[n]; for(i=1;i<=n-1;i+=2) Vol2+=(4*Int[i]);
for(i=2;i<=n-2;i+=2) Vol2+=(2*Int[i]);
Vol2*=(h/3); if(pasos < pmx) { if(fabsl(Vol2 - Vol1) > error) { Vol1 = Vol2; pasos = pasos + 1; goto otro; } }
return (Vol2); }
///////////////////////////////////////////////////////// //FUNCION QUE CALCULA EL AREA POR EL METODO DEL SIMPSON// /////////////////////////////////////////////////////////
long double simpson(long double a,long double b,int opcion,long double Y,long double error) {
long double n,h,i1,i,i2,r; int p;
n=2; p=2; h=fabsl(b-a)/2; i1=((f(opcion,a,Y)+4*f(opcion,a+h,Y)+f(opcion,b,Y))*(h/3));
otro:
n+=2; h=(fabsl(b-a))/n; i2=f(opcion,a,Y)+f(opcion,b,Y); for(i=2;i<=n-2;i+=2) i2+=2*f(opcion,a+i*h,Y); for(i=1;i<=n-1;i+=2) i2+=4*f(opcion,a+i*h,Y); i2=i2*(h/3);
if (p<=pmx) { if ((fabsl(i2-i1))<error)
{ i2=i1; ++p; goto otro; }} return (i2); }
long double f(int z,long double x,long double y)
{ long double fun; switch (z) { case 1:fun=(exp(x)*exp(y));break; case 2:fun=sin(x)*cos(y);break; case 3:fun=(2*x)/y;break; case 4:fun=(exp(x)*(y))(x)*2;break; ----> Error 1 case 5:fun=((exp(x*y))sin(2)(x*y));break; ----->Error 2 case 6:fun=(x*y)/(x+y);break; case 7:fun=log(x+y);break;
} return (fun); }
|