Business

Wednesday, 1 July 2015

Pemrograman (Metode Posisi Palsu)

Pada kesempatan ini saya akan membagikan artikel mengenai Bahasa pemrograman yaitu bahasa C++  dimana dalam bahasa C++ kita sapat menjumpai Program Borland C++ yang di gunakan Misalnya kawan ada mata kuliah nya Analisa Numerik Atau Komputasi di Perguruan Tinggi yang Kawan kawan tempati. Dalam Hal ini saja akan Membagikan tentang Metode Posisi Palsu.


#include<iostream.h>
#include<iomanip.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define epsilon 1E-13     
main()
{
long double a,b,c,f_a,f_b,f_c,f_ac,ffac;
int max=100;
int it;
char lagi;

awal:
clrscr();
it=-1;
textcolor(13);cprintf("======================================");
textcolor(10);cprintf("=");
textcolor(13);cprintf("========================================");cout<<endl;
textcolor(10);cprintf("=============================");
textcolor(12);cprintf(" Metode Posisi Palsu ");
textcolor(10);cprintf("=============================");cout<<endl;
textcolor(13);cprintf("======================================");
textcolor(10);cprintf("=");
textcolor(13);cprintf("========================================");cout<<endl;
cout<<endl;
cout<<endl;
textcolor(10);cprintf("                              2");cout<<endl;
textcolor(12);cprintf(" Persamaan yang digunakan : ");textcolor(10);cprintf(" X  + X - 3");cout<<endl;cout<<endl;
textcolor(10);cprintf(" Nilai Eror : ");cout<<epsilon<<endl<<endl;
textcolor(14);cprintf("Coba Dengan");textcolor(10);cprintf(" a=1");
textcolor(14);cprintf(" dan ");textcolor(12);cprintf("b=3 ");cout<<endl;;cout<<endl;
textcolor(10);cprintf("Masukkan Nilai a : ");cin>>a;cout<<endl;
textcolor(12);cprintf("Masukkan Nilai b : ");cin>>b;cout<<endl;
cout<<endl;
   textcolor(10);cprintf("================================================================================");cout<<endl;
    textcolor(10);cprintf("|");textcolor(11);cprintf(" No ");
   textcolor(10);cprintf("|");textcolor(12);cprintf("    a    ");
   textcolor(10);cprintf("|");textcolor(13);cprintf("    b    ");
   textcolor(10);cprintf("|");textcolor(14);cprintf("    c    ");
   textcolor(10);cprintf("|");textcolor(15);cprintf("   F(a)   ");
   textcolor(10);cprintf("|");textcolor(9);cprintf("   F(b)   ");
   textcolor(10);cprintf("|");textcolor(7);cprintf("   F(c)   ");
   textcolor(10);cprintf("|");textcolor(19);cprintf(" F(a)xF(c)");
   textcolor(10);cprintf("|");cout<<endl;
    textcolor(10);cprintf("================================================================================");cout<<endl;


   do
       {

      it+=1;
      f_a=pow(a,2)+a-3;
        f_b=pow(b,2)+b-3;
       c=((a*f_b)-(b*f_a))/(f_b-f_a);
      f_c=pow(c,2)+ c-3;
      f_ac=f_a*f_c;
      ffac=fabs(f_ac);



      textcolor(10);cprintf("|");textcolor(11);cprintf("%3d ",it);
      textcolor(10);cprintf("|");textcolor(12);cprintf("%9.2Le",a);
      textcolor(10);cprintf("|");textcolor(13);cprintf("%9.2Le",b);
      textcolor(10);cprintf("|");textcolor(14);cprintf("%9.2Le",c);
      textcolor(10);cprintf("|");textcolor(15);cprintf("%10.2Le",f_a);
      textcolor(10);cprintf("|");textcolor(9);cprintf("%10.2Le",f_b);
      textcolor(10);cprintf("|");textcolor(7);cprintf("%10.2Le",f_c);
      textcolor(10);cprintf("|");textcolor(19);cprintf("%10.2Le",ffac);
      textcolor(10);cprintf("|");
      cout<<endl;
      if(f_ac<=0)
         {
         b=c,f_b=f_c;
         }
         else
         {
         a=c;f_a=f_c;
         }
         }
   while(it<=max && fabs(f_c) >= epsilon);
       if(it<=max)
       {
      textcolor(10);cprintf("================================================================================");cout<<endl;
      textcolor(10);cprintf(" Hampiran (Pendekatan) Nilai ");
      textcolor(12);cprintf("x = %2.13Le ",c);cout<<endl;
               }
      else
      {
      textcolor(10);cprintf("================================================================================");cout<<endl;
      textcolor(10);cprintf(" hampiran tidak mencukupi... tambah nilai toleransi batas ");
      cout<<endl;
        }

      textcolor(2);cprintf(" Masih Mau dengan Epsilon yang Berbeda ? [Y/T] : \n");

        lagi=getche();
        if(lagi=='Y' || lagi=='y')

        goto awal;
getche();
}

0 komentar:

Post a Comment