Metode Bagi Dua
#include<stdio.h>
#include<iomanip.h>
#include<conio.h>
#include<math.h>
#include<iostream.h>
#define epsilon 1E-13
main()
{
int it;
long double a=-1,b=2,T,fa,fb,fT,faT,e=2.718281828,KET;
cout<<"**************************************************************************";cout<<endl;
cout<<" ANALISIS NUMERIK / Metode Bagi Dua ";cout<<endl;
cout<<"**************************************************************************";cout<<endl;
printf("============================================================================");cout<<endl;
printf("| it| a | b | f(a) | f(b) | T | f(T) |f(a)f(T)| Ket |");cout<<endl;
printf("============================================================================");cout<<endl;
it=0;
fa=pow(e,a)-6*pow(a,2);
fb=pow(e,b)-6*pow(b,2);
T=(a+b)/2;
fT=pow(e,T)-6*pow(T,2);
faT=fa*fT;
printf("|%3d| %5.1Le| %5.1Le|%5.1Le |%5.1Le |%5.1Le | %5.1Le |%5.1Le |",it,a,b,fa,fb,T,fT,faT);cout<<endl;
do
{
if(faT<0)
{b=T;fT=fb;}
else
{a=T;fT=fa;}
it=it+1;
T=(a+b)/2;
fT=pow(e,T)-6*pow(T,2);
faT=fa*fT;
KET=fabs(fT);
printf("|%3d| %5.1Le| %5.1Le|%5.1Le |%5.1Le | %5.1Le | %5.1Le |%5.1Le |",it,a,b,fa,fb,T,fT,faT);
if(KET<=epsilon)
{printf("SELESAI|");}
else
{cout<<"LANJUT |";}
cout<<endl;
}
while(it<=100 && fabs(fT)>=epsilon);
printf("============================================================================");cout<<endl;
printf("==> Jadi nilai akarnya ( %3.5Le ) pada iterasi ke %3d .",T,it);
getche();
}
0 komentar:
Post a Comment