-
Notifications
You must be signed in to change notification settings - Fork 4
/
2.c
66 lines (61 loc) · 1.59 KB
/
2.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
#include "math.h"
#include "stdio.h"
double lrgs(a,b,eps,f)
double a,b,eps,(*f)();
{
int m,i,j;
double s,p,ep,h,aa,bb,w,x,g;
double t[5]={-0.9061798459,-0.5384693101,0.0,0.5384693101,0.9061798459};
double c[5]={0.2369268851,0.4786286705,0.5688888889,0.4786286705,0.2369268851};
m=1;
h=b-a; s=fabs(0.001*h);
p=1.0e+35;ep=eps+1.0;
while ((ep>=eps)&&(fabs(h)>s))
{
g=0.0;
for (i=1;i<=m;i++)
{
aa=a+(i-1.0)*h; bb=a+i*h;
w=0.0;
for (j=0;j<=4;j++)
{
x=((bb-aa)*t[j]+(bb+aa))/2.0;
w=w+(*f)(x)*c[j];
}
g=g+w;
}
g=g*h/2.0;
ep=fabs(g-p)/(1.0+fabs(g));
p=g; m=m+1; h=(b-a)/m;
}
return (g);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
double c;
double bb(x)
double x;
{
double y;
y=c*x*x;
return (y);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
main()
{
double a,b,eps,g,bb(double);
a=0.0;b=2*3.1415926;eps=0.000001;
c=1;
g=lrgs(a,b,eps,bb);
printf("\n" );
printf("g=%13.5e\n", g);
printf("\n" );
c=2;
g=lrgs(a,b,eps,bb);
printf("\n" );
printf("g=%13.5e\n", g);
printf("\n" );
}