Senin, 04 Juni 2012

Metode Integrasi Numerik

Berikut adalah Kodingan dari Integrasi Numerik,,
akan lebih bagus jika ada tampilan outputnya,, namun untuk sementara ini saja dulu


#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

float f(float xo)
{
float fx;
 fx=pow(xo,3)-(3*xo)+2;
 return fx;
}

int pil1()
{
  float btsa,btsb,h,fxo,fx1,fx2,fx3,n,i,sum,Deltafx;
  cout<<"Soal Latihan No. 1 \n";
  cout<<"===================================\n";
  cout<<"Input Nilai Batas Atas (b) : ";cin>>btsa;
  cout<<"Input Nilai Batas Bawah (a) : ";cin>>btsb;
  cout<<"Input Nilai n : ";cin>>n;cout<<endl;
  h=(btsa-btsb)/n;
  sum=f(btsb);

  for(i=1;i<n;i++)
     {
       sum=sum+2*(f(btsb+(i*h)));
     }

  fxo=(h*(sum+f(btsa)))/2;
  fx1=(pow(btsa,4)/4)-(3*(pow(btsa,2))/2)+(2*btsa);
  fx2=(pow(btsb,4)/4)-(3*(pow(btsb,2))/2)+(2*btsb);
  Deltafx=fx1-fx2;
  fx3=Deltafx-fxo;

  cout<<"1.Perhitungan Metode Numerik : "<<fxo<<"\n";
  cout<<"2.Perhitungan Metode Analitik : "<<Deltafx<<"\n";
  cout<<"3.Eror : "<<fabs(fx3);
  cout<<endl;
getch();
}

int pil2()
{
  float btsa,btsb,h,fxo,fx1,fx2,fx3,n,i,sum,Deltafx;
  cout<<"Soal Latihan No. 2 \n";
  cout<<"===================================\n";
  cout<<"Input Nilai Batas Atas (b) : ";cin>>btsa;
  cout<<"Input Nilai Batas Bawah (a) : ";cin>>btsb;
  cout<<"Input Nilai n : ";
  cin>>n;cout<<endl;
  h=(btsa-btsb)/n;
  sum=f(btsb);

  for(i=1;i<n;i++)
    {
      sum=sum+2*(f(btsb+(i*h)));
    }

  fxo=(h*(sum+f(btsa)))/2;
  fx1=(2.79487*btsa) + (0.312151*pow(btsa,2))/2;
  fx2=(2.79487*btsb) + (0.312151*pow(btsb,2))/2;
  Deltafx=fx1-fx2;
  fx3=Deltafx-fxo;

  printf("1.Perhitungan Metode Numerik : %.4f\n",fxo);
    //cout<<"1.Perhitungan Metode Numerik : "<<fxo<<"\n";
  printf("2.Perhitungan Metode Analitik : %.4f\n",Deltafx);
   // cout<<"2.Perhitungan Metode Analitik : "<<Deltafx<<"\n";
  printf("3. Error : %.4f",fabs(fx3));
   // cout<<"3.Eror : "<<fabs(fx3);
  cout<<endl;
getch();
}

int main()
{
  int angka;
  char huruf;
    awal:
    cout<<"MENU INTEGRASI NUMERIK (Modul Pert. 10) :\n";
    cout<<"METODE TRAPESIUM\n\n";
    cout<<"=============================================\n";
    cout<<"1. Soal No. 1\n";
    cout<<"2. Soal No. 2\n";
    cout<<"3. KELUAR\n";
    cout<<"Silahkan Input Pilihan Anda [1-3] : ";
    cin>>angka;

    if (angka==1)
      {
        pil1();cout<<"\n";
        goto awal;
      }
    else if (angka==2)
      {
        pil2();
        cout<<"\n";
        goto awal;
      }
    else {
       cout<<"Anda Yakin Akan Keluar Dari Program ? [Y/T] : ";
       cin>>huruf;cout<<endl;
       if (huruf=='Y' || huruf=='y')
          {
            cout<<"Semoga Bermanfaat dan Terima Kasih... (^_^)";
            exit(0);}
       else if (huruf=='T' || huruf=='t')
          {cout<<"\n";
           goto awal;}
    }
getch();
}

Tidak ada komentar:

Posting Komentar