include iostream include iomanip include math include stdio include st

 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream.h>
#include <iomanip.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
double X[100],Y[100],dY[100],DY[100],d2Y[100],D2Y[100],pog1[100],pog2[100],h,I;
int i,a,b,k,r,v,m;
double f(double x)
{
double t;
t=log(x)-5*pow(sin(x),2);
return(t);
}
double Gauss3(double A,double B,double M)
{
double h,x0,x1,x2,s=0,integral;
int i;
h=(B-A)/M;
x0=A+h/2;
x1=x0-(h/2)*0.7745966692;
x2=x0+(h/2)*0.7745966692;
for(i=1;i<=m;i++)
{
s+=0.555555555555556*f(x1)+0.888888888888889*f(x0)+0.555555555555556*f(x2);
x0=x0+h;
x1=x0-(h/2)*0.7745966692;
x2=x0+(h/2)*0.7745966692;
}
integral=(h/2)*s;
return (integral);
}
void main()
{
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"Vibirete shag:\n"<<"1 h=0.2\n"<<"2 h=0.1\n"<<"3 h=0.05\n";
cin>>r;
switch(r)
{
case 1:
h=0.2;
break;
case 2:
h=0.1;
break;
case 3:
h=0.05;
break;
default:
cout<<"Vibrano ne dopustimoe zna4enie";
}
cout<<"Viberete m:\n1 m=10\n2 m=20\n3 m=40\n";
cin>>v;
switch(v)
{
case 1:
m=10;
break;
case 2:
m=20;
break;
case 3:
m=40;
break;
default:
cout<<"Vibrano ne dopustimoe zna4enie";
}
k=(b-a)/h;
for(i=1;i<=k+1;i++)
{
X[i]=a+(i-1)*h;
Y[i]=f(X[i]);
}
//первая производная
dY[1]=-(3*Y[1]-4*Y[2]+Y[3])/(2*h);
dY[k+1]=(Y[k-1]-4*Y[k]+3*Y[k+1])/(2*h);
for(i=2;i<=k;i++) dY[i]=(Y[i+1]-Y[i-1])/(2*h);
for(i=1;i<=k+1;i++) DY[i]=1/X[i]-5*sin(2*X[i]);
//вторая производная
for(i=1;i<=k+1;i++) D2Y[i]=-1/(X[i]*X[i])-10*cos(2*X[i]);
for(i=2;i<=k;i++) d2Y[i]=(Y[i-1]-2*Y[i]+Y[i+1])/(h*h);
for(i=1;i<=k+1;i++)
{
pog1[i]=fabs(fabs(dY[i])-fabs(DY[i]));
pog2[i]=fabs(fabs(d2Y[i])-fabs(D2Y[i]));
}
cout<<"X\tY\tdY\tDY\tpogr\td2Y\tD2Y\tpogr\n"<<endl;
for(i=1;i<=k+1;i++) cout<<X[i]<<setw(10)<<Y[i]<<setw(10)<<dY[i]<<setw(10)<<DY[i]<<setw(10)<<pog1[i]<<setw(10)<<d2Y[i]<<setw(10)<<D2Y[i]<<setw(10)<<pog2[i]<<endl;
I=Gauss3(a,b,m);
cout<<endl<<"Integral="<<I<<endl;
}