include iostream include stdio include math include stdlib include win

 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
#include <iostream.h> #include <stdio.h> #include <math.h> #include <stdlib.h> #include <windows.h> #include <iomanip.h>
void main() {
int n,i,k;
float h,c1,c2,c,d1,d2,d,fx,a,b,k1,k2,m,H,runge;
float p[9999],q[9999],betta[9999],gamma[9999],fi[9999],alfa[9999]; float y[9999],u[9999],v[9999],x[9999],Y[9999];
c1=d1=1.0;
c2=d2=1.0;
fx=0.0;
cout<<"Vvedite kraia otrezka [a,b] i 4islo uzlov n"<<endl; cout<<endl<<"a=";
cin>>a;
cout<<endl<<"b=";
cin>>b;
cout<<endl<<"n=";
cin>>n; cout<<endl<<"A tak ge parametri c,d,k1,k2,m"<<endl; cin>>c>>d>>k1>>k2>>m;
x[0]=a;
h=(b-a)/n;
betta[0]=c1*h-c2;
gamma[0]=c2;
fi[0]=h*c;
alfa[0]=0;
for(i=1;i<n;i++)
{
x[i]=x[i-1]+h; p[i]=(k1+k2*x[i])/(x[i]*x[i]-1); q[i]=m/sqrt(1-x[i]*x[i]); fi[i]=fx*h*h; alfa[i]=1-(1/2)*p[i]; betta[i]=q[i]*h*h-2;
gamma[i]=1+(1/2)*p[i]*h; }
alfa[n]=-d2; betta[n]=h*d1+d2; fi[n]=h*d; v[0]=gamma[0]/betta[0]; u[0]=fi[0]/betta[0]; for(i=1;i<n;i++)
{
v[i]=-gamma[i]/(betta[i]+alfa[i]*v[i-1]); u[i]=(fi[i]-alfa[i]*u[i-1])/(betta[i]+alfa[i]*v[i-1]);
}
y[n]=u[n]; for(i=n-1;i>0;i--)
y[i]=u[i]+v[i]*y[i+1];
cout<<" i"<<" x "<<" y"<<endl; for(i=0;i<n;i++)
{
cout.width(4); cout<<i; cout.width(5); cout<<x[i]; cout.width(14); cout<<y[i]<<endl;
}
H=(b-a)/(2*n); betta[0]=c1*H-c2; gamma[0]=c2; fi[0]=H*c; alfa[0]=0;
k=2*n; for(i=1;i<k;i++) {
x[i]=x[i-1]+H; p[i]=(k1+k2*x[i])/(x[i]*x[i]-1); q[i]=m/sqrt(1-x[i]*x[i]); fi[i]=fx*H*H; alfa[i]=1-(1/2)*p[i]; betta[i]=q[i]*H*H-2; gamma[i]=1+(1/2)*p[i]*H;
}
alfa[k]=-d2; betta[k]=H*d1+d2; fi[k]=H*d;
v[0]=gamma[0]/betta[0]; u[0]=fi[0]/betta[0]; for(i=1;i<k;i++)
{
v[i]=-gamma[i]/(betta[i]+alfa[i]*v[i-1]);
u[i]=(fi[i]-alfa[i]*u[i-1])/(betta[i]+alfa[i]*v[i-1]); }
Y[k]=u[k]; for(i=2*n-1;i>0;i--)
Y[i]=u[i]+v[i]*Y[i+1]; cout<<" i"<<" x "<<" Y"<<endl; for(i=0;i<k;i++)
{
cout.width(4); cout<<i; cout.width(5); cout<<x[i]; cout.width(14); cout<<Y[i]<<endl;
}
cout<<"pogre6nost' po pravily runge:"<<endl; for(i=0;i<n;i++)
{
runge=(Y[2*i]-y[i]);
cout<<runge<<endl; }
system("PAUSE"); }