-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixedpoint.cpp
More file actions
60 lines (59 loc) · 1.1 KB
/
fixedpoint.cpp
File metadata and controls
60 lines (59 loc) · 1.1 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
#include<bits/stdc++.h>
#define double long double
using namespace std;
const double eps=1e-9;
const double alp=0.08;
double fun1(double x,double number){
return 0.5*(x+number/x);
}
double fun2(double x){
// return x-alp*(x*x-x-4);
return 2*sin(x)-2;
}
void sqrtfun(){
double num=5.0;
double g=2.0;
int it=0;
while(1){
it++;
double g_next=fun1(g,num);
if(fabs(g_next-g)<eps){
g=g_next;
break;
}
g=g_next;
if(it==100000){
cout<<"invalid num"<<endl;
return;
}
}
cout<<"Num: "<<num<<" guess: "<<g<<" itterations: "<<it<<endl;
}
void modifiedalpha(){
ofstream cout;
cout.open ("data4.txt");
double g=0;
int it=0;
while(1){
it++;
double g_next=alp*fun2(g)-(1-alp)*g;
cout<<fabs(g_next-g)<<" "<<it<<endl;
if(fabs(g_next-g)<eps){
g=g_next;
break;
}
g=g_next;
// if(it==100000){
// cout<<"invalid"<<endl;
// return;
// }
}
// cout<<"guess: "<<g<<" itterations: "<<it<<endl;
// cout<<2*sin(g)-g<<endl;
}
int main(){
cout<<setprecision(9)<<fixed;
// sqrtfun();
modifiedalpha();
return 0;
}