Senin, 04 Juni 2012

Differensiasi Numerik

Berikut adalah Kodingan dari Differensiasi Numerik


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

int pil1()
{
  float xo,hit1,hit2,h=0.2,fx,fxo,fh1,fh2;
  cout<<"TAKSIRAN 2 TITIK \n";
  cout<<"===================================\n";
  cout<<"Input Nilai Xo : ";cin>>xo;cout<<endl;
  hit1=xo+h;
  hit2=xo-h;
  fh1=1.79759 + (0.311423*hit1);
  fh2=1.79759 + (0.311423*hit2);
  fx=(fh1-fh2)/(2*h);
  fxo=0.311423-fx;
   
  cout<<"1.Perhitungan Metode Numerik : "<<fx<<"\n";
  cout<<"2.Perhitungan Metode Analitik : "<<"0.311423\n";
  cout<<"3.Eror : "<<fabs(fxo);
  cout<<endl;
  getch();
}


int pil2()
{
  float xo,hit1,hit2,h1=0.4,h2=0.2,fx,fxo,fh,fh1,fh2;
  cout<<"TAKSIRAN 3 TITIK \n";
  cout<<"===================================\n";
  cout<<"Input Nilai Xo : ";cin>>xo;cout<<endl;
  hit1=xo+h2;
  hit2=xo-h1;
  fh=1.79759 + (0.311423*xo);
  fh1=1.79759 + (0.311423*hit1);
  fh2=1.79759 + (0.311423*hit2);
  fx=(h1*h1*(fh1+((h2*h2)-((h1*h1)*fh))-(h2*h2)*fh2))/(h1*h2)*(h1+h2);
  fxo=0.311423-fx;

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

int pil3()
{
  float xo,hit1,hit2,hit3,hit4,h=0.2,fx,fxo,fh1,fh2,fh3,fh4;
  cout<<"TAKSIRAN 5 TITIK \n";
  cout<<"===================================\n";
  cout<<"Input Nilai Xo : ";cin>>xo;cout<<endl;
  hit1=xo+h;
  hit2=xo-h;
  hit3=xo-(2*h);
  hit4=xo+(2*h);
  fh1=1.79759 + (0.311423*hit1);
  fh2=1.79759 + (0.311423*hit2);
  fh3=1.79759 + (0.311423*hit3);
  fh4=1.79759 + (0.311423*hit4);
  fx=(fh3-(8*fh2)+(8*fh1)-fh4)/(12*h);
  fxo=0.311423-fx;

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

int main()
{
  int angka;char huruf;
  awal:
  cout<<"MENU DIFFERENSIASI NUMERIK :\n\n";
  cout<<"======================================\n";
  cout<<"1. TAKSIRAN 2 TITIK\n";
  cout<<"2. TAKSIRAN 3 TITIK\n";
  cout<<"3. TAKSIRAN 5 TITIK\n";
  cout<<"4. Keluar\n";
  cout<<"Silahkan Input Pilihan Anda [1-4] : ";cin>>angka;

  if (angka==1)
    {
      pil1();cout<<"\n";
      goto awal;
    }
  else if (angka==2)
    {
      pil2();cout<<"\n";
      goto awal;}
  else if (angka==3)
    {
      pil3();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