-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrombger.c
81 lines (70 loc) · 1.63 KB
/
rombger.c
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
/*************************************************************************
> File Name: rombger.c
> Author:KID_XiaoYuan
> Mail:[email protected]
> Created Time: 2017年05月22日 星期一 21时18分58秒
************************************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
double ROMBGER(double a, double b, double eps,double al,double ma,double mi);
double Func(double);
int main()
{
double a,b,eps,al,ma,mi;
scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&eps,&al,&ma,&mi);
printf("%.10lf\n",ROMBGER(a,b,eps,al,ma,mi));
return 0;
}
double ROMBGER(double a, double b, double eps,double al,double ma,double mi)
{
double l,h,r,s,k,l0,m,n;
int j,q;
double *t;
t = (double*)calloc(11,sizeof(double));
if(t == NULL)
exit(1);
l = b - a;
h = l ;
t[0] = (Func(a) + Func(b)) * l * 0.5;
for(q = 0; q <= ma-1; q++)
{
r = h;
h *= 0.5;
k = h;
s = Func(a+k);
do
{
k += r;
if(fabs(k) < fabs(l))
{
s += Func(a+k);
}
}while(fabs(k) < fabs(l));
t[q+1] = t[q] * 0.5 + h * s;
l0 = 1;
for(j=q;j >= 0; j--)
{
l0 *= 0.25;
m = (t[j+1] - t[j])/(1-l0);
t[j] += m;
}
n = t[0];
if(fabs(n) >= al)
{
m /= n;
}
if(fabs(m) < eps && q > mi)
{
r = t[0];
free(t);
return(r);
}
}
free(t);
return(r);
}
double Func(double x)
{
return (exp(x) * x *x);
}