Metode Secant
#include<iomanip.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define epsilon 1E-15
main()
{
int it;
long double x[100],fx[100],fs;
textcolor(10);cprintf(" Nama : Asrul Maiwa");cout<<endl;
textcolor(10);cprintf(" NIM : 1312140015");cout<<endl;
textcolor(10);cprintf(" Kelas : SAINS(C)");cout<<endl;
textcolor(2);cprintf("================================================");cout<<endl;
textcolor(12);cprintf(" METODE SECANT ");cout<<endl;
textcolor(2);cprintf("================================================");cout<<endl;
cout<<endl;
textcolor(12);cprintf(" 1. 1+x-tan(x)= 0");cout<<endl;
cout<<endl;
textcolor(10);cprintf("================================================");cout<<endl;
textcolor(10);cprintf("|");
printf(" Iterasi ");
textcolor(10);cprintf("|");
printf(" x ");
textcolor(10);cprintf("|");
printf(" f(x) ");
textcolor(10);cprintf("|");
printf(" KETERANGAN ");
textcolor(10);cprintf("|");cout<<endl;
textcolor(10);cprintf("================================================");cout<<endl;
it=0;
x[it]=1;
fx[it]=1+x[it]-tan(x[it]*3.14/180);
textcolor(10);cprintf("|");
printf(" %4d ",it);
textcolor(10);cprintf("|");
printf("%10.2Le ",x[it]);
textcolor(10);cprintf("|");
printf("%10.2Le ",fx[it]);
textcolor(10);cprintf("|");
printf(" ");
textcolor(10);cprintf("|");cout<<endl;
it=1;
x[it]=2;
fx[it]=1+x[it]-tan(x[it]*3.14/180);
textcolor(10);cprintf("|");
printf(" %4d ",it);
textcolor(10);cprintf("|");
printf("%10.2Le ",x[it]);
textcolor(10);cprintf("|");
printf("%10.2Le ",fx[it]);
textcolor(10);cprintf("|");
printf(" ");
textcolor(10);cprintf("|");cout<<endl;
do
{
it+=1;
x[it]=x[it-1]-((fx[it-1]*(x[it-1]-x[it-2]))/(fx[it-1]-fx[it-2]));
fx[it]=1+x[it]-tan(x[it]*3.14/180);
fs=fabs(x[it]-x[it-1]) ;
textcolor(10);cprintf("|");
printf(" %4d ",it);
textcolor(10);cprintf("|");
printf("%10.2Le ",x[it]);
textcolor(10);cprintf("|");
printf("%10.2Le ",fx[it]);
textcolor(10);cprintf("|");
if(fs<=epsilon)
{
printf(" SELESAI ");
}
else
{
printf(" LANJUT ");
}
textcolor(10);cprintf("|");
cout<<endl;
if(it % 2 == 0 )
{
textcolor(10);cprintf("|");
textcolor(2);cprintf(" Nilai Akar : %20.13Le", x[it]);
textcolor(10);cprintf(" |");cout<<endl;
}
}
while(it<=90 && fs>=epsilon);
textcolor(10);cprintf("================================================");cout<<endl;
cout<<endl;
textcolor(12);cprintf(" Nilai Akar : %20.13Le", x[it]);cout<<endl;
printf(" Selesai Pada Iterasi Ke- %d",it);cout<<endl;
getche();
}
0 komentar:
Post a Comment