-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEX_SEARCH_BOOM.cpp
More file actions
52 lines (46 loc) · 1.18 KB
/
EX_SEARCH_BOOM.cpp
File metadata and controls
52 lines (46 loc) · 1.18 KB
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
/*
EXHAUSTVE SEARCH METHOD
Sudharsan Neelamegam
*/
#include <bits/stdc++.h>
#include <math.h>
#include <iomanip>
using namespace std;
float fun(float x)
{
float result;
result = pow(x-1,2)-(0.01*pow(x,4)); //ENTER THE FUNCTION VALUE IN TERMS OF x AS PER IN QUESTION
return result;
}
float fun();
int main()
{
float x1=0,x2,x3,b,a,n,dx,fx1,fx2,fx3,value;
int c=0;
cout<<"Enter the interval a,b and intermediate points n:";
cin>>a>>b>>n;
int ivl=(n/2)+2;
cout<<"iter x1 x2 x3 fx1 fx2 fx3 cond"<<endl;
dx=(b-a)/n;
for(int i=0;i<ivl;i++)
{
x1=a;
x2=a+dx;
x3=a+(2*dx);
fx1=fun(x1);
fx2=fun(x2);
fx3=fun(x3);
if( (fx2<=fx1 && fx2<=fx3) )
{
c=1;
cout<<fixed;
cout<<i<<setprecision(2)<<" "<<x1<<" "<<x2<<" "<<x3<<" "<<fx1<<" "<<fx2<<" "<<fx3<<" "<<c<<endl;
break;
}
cout<<fixed;
cout<<i<<setprecision(2)<<" "<<x1<<" "<<x2<<" "<<x3<<" "<<fx1<<" "<<fx2<<" "<<fx3<<" "<<c<<endl;
a+=dx;
}
cout<<"Req Range is : ["<<x1<<","<<x3<<"]";
return 0;
}