Jumat, 25 Mei 2012

METODE TRAPEZOIDAL

Trapezoidal is one of methods that used to approximate numerical integration. Although we can implemented based to mathematical subroutine in this algorithm, we can also use Excel worksheet. It’s very simple, because we can generate formula with ordinary  mathematic function.


METODE  TRAPEZOIDAL

#include
#include
#include
float f(float x)
  {
   return(6-6*x*x);
  }

main()
  {
   float a,b,h,y,Ar,A;
   int n,k,sw;
   char er;
   ulang:
   clrscr();
   gotoxy(65,1);textbackground(4);textcolor(15);
   cputs("pens");textbackground(1);textcolor(14);

   gotoxy(25,3);printf("Program Metode Trapezoidal");
   gotoxy(10,5);printf("Entry data :");
   gotoxy(12,7);  printf("a      b     n   k  SW    y       A");
   gotoxy(10,8);printf(".....  .....  ..");
   gotoxy(10,8);scanf("%f",&a);gotoxy(10,8);printf("%5.2f",a);
   gotoxy(17,8);scanf("%f",&b);gotoxy(17,8);printf("%5.2f",b);
   gotoxy(24,8);scanf("%d",&n);gotoxy(24,8);printf("%2d",n);

   isi:
   gotoxy(20,23);printf("Ada kesalahan      : .   isi y/n");
   gotoxy(41,23);er=getche();
   switch(er)
    { case 'y' : goto ulang;
      case 'n' : goto terus;
      default  : goto isi;
    }
   terus:;
   h=(b-a)/n; Ar=0;
   gotoxy(10,5);printf("Hasil :                   ");
   for(k=1;k<=n+1;k++)
     {
      if(k==1||k==n+1) sw=1;
       else sw=2;
      y=f(a+(k-1)*h);
      A=sw*y*h/2;
      Ar=Ar+A;

      gotoxy(28,7+k);printf("%2d %2d  %7.4f  %7.4f",k,sw,y,A);
      getch();
     }
     gotoxy(25,n+k+3);printf("Atot            : ") ;
     gotoxy(44,n+k+3);printf("%7.4f",Ar);
   akhir:
   gotoxy(20,23);printf("Proses yang lain   : .   isi y/n");
   gotoxy(41,23);er=getche();
   switch(er)
    { case 'y' : goto ulang;
      case 'n' : goto sli;
      default  : goto akhir;
    }
   sli:
   clrscr();
   gotoxy(20,10);printf("Thanks   . . . . .  your attention!");
   gotoxy(1,23);
   getch();
  }

Tidak ada komentar:

Posting Komentar