-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOUNDING_PHASE_BOOM.cpp
More file actions
69 lines (51 loc) · 1.25 KB
/
BOUNDING_PHASE_BOOM.cpp
File metadata and controls
69 lines (51 loc) · 1.25 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
BOUNDING PHASE METHOD
Sudharsan Neelamegam
**** NOTE :Below float fun(float x), put the funation as given in the question in terms of x
*/
#include <bits/stdc++.h>
#include <math.h>
#include <iomanip>
using namespace std;
float fun(float x)
{ float result;
result=pow(100-x,2);//ENTER FUNCTION IN TERMS OF X AS GIVEN IN QUESTION PROPERLY HERE
return result;
}
float fun();
int main()
{
float x0,k=0,xk,xkp,n,fxk,fxkp,fmm,fpp,d,f0,v=0;
float c,con=0;
cout<<"Enter the initial guess value x0 and increment value :";
cin>>x0>>d;
cout<<"k xk x(k+1) fxk fx(k+1) cond"<<endl;
fmm=x0-d;
f0=x0;
xk=f0;
fpp=x0+d;
xkp=fpp;
while(v==0)
{
float a=fun(fmm),b=fun(xk),c=fun(xkp);
if((a>=b) && (b>=c))
{
d=d*1;
}
else
{
d=d*(-1);
}
if(c>b)
{ con++;
cout<<k<<" "<<xk<<" "<<xkp<<" "<<b<<" "<<c<<" "<<con<<endl;
break;
}
cout<<k<<" "<<xk<<" "<<xkp<<" "<<b<<" "<<c<<" "<<con<<endl;
xk=xkp;
xkp=xk+((pow(2,k+1))*d);
k++;
}
cout<<"Req range is: ("<<(xk+(pow(2,k-1)*d))<<","<<xkp<<")";
return 0;
}