-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bisection.cpp
158 lines (133 loc) · 2.84 KB
/
Bisection.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#define cek 17 //for like as \t to setw command
#include <iostream>
#include <stdio.h>
#include <conio.h> //yogi
#include <math.h>
#include <cmath>
#include <iomanip>
#include <windows.h>
using namespace std;
float f(float x);
void yogi()
{
float a,b,c,lebar;
float epsilon;
int i=0;
cout << endl;
cout <<"\tBATAS PERTAMA (a) : ";
cin >>a;
cout <<"\tBATAS KEDUA (b) : ";
cin >>b;
cout <<"\tEPSILON (GALAT) : ";
cin >>epsilon;
cout <<endl;
cout <<"\t\t\tNB : UPDATE isinya adalah [x1,x2] , dimana x1 Adalah [A Update] dan x2 adalah [B Update]\n";
cout <<"\t\t\t : SELISIH UPDATE isinya adalah [x2-x1] , dimana x1 Adalah [A Update] dan x2 adalah [B Update] ";
cout <<endl;
for (int yogis=0 ; yogis <140 ; yogis++)
{
cout <<"_";
}
cout <<endl;
if (f(a)*f(b)>0){
}
else{
cout <<"i"<<setw(cek)<<"a"<<setw(cek)<<"xr"<<setw(cek)<<"b"<<setw(cek)<<"f(a)";
cout <<setw(cek)<<"f(xr)"<<setw(cek)<<"f(b)"<<setw(cek)<<"UPDATE"<<setw(cek)<<"Selisih UPDATE"<<endl;
for (int yogis=0 ; yogis <140 ; yogis++)
{
cout <<"_";
}
cout <<endl;
do
{
c=(a+b)/2;
f(c);
if(c<epsilon || i>40){
}
else{
if(f(a)*f(c)<0){
cout <<i<<setw(cek)<<a<<setw(cek)<<c<<setw(cek)<<b<<setw(cek)<<f(a)<<setw(cek);
cout <<f(c)<<setw(cek)<<f(b)<<setw(cek)<<"[A,XR]";
b=c;
lebar= abs(b-a);
cout<<setw(cek)<<lebar<<endl;
cout<<endl;
}
else{
cout<<i<<setw(cek)<<a<<setw(cek)<<c<<setw(cek)<<b<<setw(cek)<<f(a)<<setw(cek);
cout<<f(c)<<setw(cek)<<f(b)<<setw(cek)<<"[XR,B]";
a=c;
lebar= abs(b-a);
cout<<setw(cek)<<lebar<<endl;
cout<<endl;
}
i++;
}
}
while( (lebar > epsilon) );
for (int yogis=0 ; yogis <66 ; yogis++)
{
cout <<"_";
}
cout <<endl;
cout<<"Hampiran Akarnya = "<<c<<endl;
cout<<"Banyaknya Iterasi : "<<i;
}
}
float f(float x)
{
float e=2.71828182845904523536;
float hasil,hasil2,hasil3,hasil4;
hasil = x*(-1);
hasil3 = pow(e,hasil);
hasil4=hasil3-x;
return (hasil4);
}
int main()
{
yogiLabel:
// SetConsoleDisplayMode(GetStdHandle(STD_OUTPUT_HANDLE),CONSOLE_FULLSCREEN_MODE,0);
//fullscreen
system("mode 650");
//fixed belakang koma precission with it
cout << fixed;
cout.precision(4);
//output
system("Color 0A");
cout<<" Created On Thursday 10.38am - 09/27/2018 | MTK DISKRIT \n";
cout<<"________FULLSCREEN VIEW 650 PIXEL__________| 17615006 [NIM]";
puts("\n\n\n\n\tMETHOD - BISECTION [ BAGI DUA ]");
for (int yogis=0 ; yogis <66 ; yogis++)
{
cout <<"_";
}
cout <<endl;
cout<<"\n\n\tDiketahui \t: Fungsi\t= F(x)=exp(-x)-x\n";
cout <<endl;
yogi();
cout <<endl <<endl;
//looping to exit or nah
for(int line=0; line <66; line++)
{
cout <<"_";
}
char y;
cout <<endl <<"Input (Y) to Try Again & else for exit : ";
cin>>y;
while(y == 'y')
{
system("cls");
goto yogiLabel; //goto label yogi
while(y == 'n')
{
system("exit"); // system keluar jika y='n/N'
while(0)
{
break;
}
}
}
getch();
return 1;
}