Вы находитесь на странице: 1из 17

2010 .

: f ( x) = x + f ( x)
x0 = 0 , y0 = f ( x0 ) = 0 , x [ a; b] .
h.
b

L2 ( x ) . R = I Lx ( x)dx , I = f ( x ) dx -
. a =0; b =1; h = 0,1 .
:
1)
- .
2) L2 ( x )
. ,
.
3)
.
:

:
-
, .
,
, , .
,
,
.

, .
-

r (x0,y0,h,m)

y=f(x, y)

x0,y0,
h0,E,b
n=](b-x0)/h0[ +1

x0,y0 -
h0 - ( )
E
-
b
- [x0;b]
n
] [

-
-

x0,y0,
h0
i=1,n

h=h0
m=1
-
r((x0),(y0),(h),(m))

y

y=r()

y1=y; h=h/2
x=x0; y=y0
m=2m

y=r()

-
r((x),(y),(h),(m))

y

|y-y1|<E

x0=x0+h0
y0=y

x0,y0,
h,m

y0 -
x0
h - ,

m -

r( )
j=1, m


:
x,y -
h -
m -
h0.

y

-

x=x+h

r=y

- 4-
:

yi+1=yi+h/6(k1+2k2+2k3+k4),
: k1=f(xi,yi)
k2=f(x i+h/2, y i+h*k1/2)
k3=f(x i+h/2, y i+h*k2/2)
k4=f(x i+h, yi+h*k 3)

-
double f(double x, double y) //
{
//
return pow(x,0.5)+pow(y,0.5);
}
double r(double x, double y, double h, int m) //
{
for(int j=0; j<m;j++)
{
double k1=f(x,y);
double k2=f(x+h/2, y+h*k1/2);
double k3=f(x+h/2, y+h*k2/2);
double k4=f(x+h, y+h*k3);
y=y+(h/6)*(k1+2*k2+2*k3+k4);
x=x+h;
}
return y;
}
void ODU(double x0, double y0, double h0, double eps, double b, double* x_arr,
double* y_arr)
{
// x0,y0 -
// h0 - ( )
// eps
// b
// x_arr - f(x)
// y_arr - f(x)
int n=((b-x0)/h0)/1+1; //
x_arr[0]=x0;
y_arr[0]=y0;
for(int i=1; i<n; i++)
{
double h=h0;
int m=1;
double y=r(x0,y0,h,m); // - r()
double z;
do{
z=y;
h=h/2;
double x=x0;

y=y0;
m=2*m;
y=r(x,y,h,m);// - r()
}while(fabs(y-z)>eps);
x0=x0+h0;
y0=y;
x_arr[i]=x0;
y_arr[i]=y0;
// y0 - x0
// h - ,
// m -

.
void Gauss(double** Z, double* Y)
{
int n=3;
double X[3];
double A[3][3]; //
double B[3]; //
int i, j, k; //
for( i = 0; i < n; i++ ) // A
{
for( j = 0; j < n; j++ )
A[i][j] = Z[i][j];
B[i] = Y[i]; //
X[i] = 0;
}
for( k = 0; k < n-1; k++ )
for( i = k+1; i < n; i++ ) //
{
double r = A[i][k] / A[k][k];
for( j = k; j < n; j++ )
A[i][j] -= A[k][j] * r;
B[i] -= B[k] * r;
}
for( i = n-1; i >= 0; i-- )
{
double s = 0;
for( j = i+1; j < n; j++ )
s += A[i][j] * X[j];
X[i] = ( B[i] - s ) / A[i][i];
}
c1=X[0];
c2=X[1];
c3=X[2];
}


f(x)

a, b,
E

a, b -
E
-

n=2
h=(b-a)/n

S=[f(a)+4*f((a+b)/2)+
+f(b)]*(h/3)

h -
n -

S -

n=2*n; h=(b-a)/n
s1=s; c=4; x=a
s=f(a)+f(b)
i=1,n-1
x=x+h
s=s+c*f(x)
c=6-c

s = s * h/3

h, n,
s1, s

|s-s1|/15<E

E, s,
n, h

S -
n -

E -
h -

double f(double x) //
{
return c3*pow(x,2.)+c2*x+c1;
}
double integ_point(double a, double b, double eps, double* y)
//
{
double n=10;
double h=(b-a)/n;
double s=0;

for(int k=0; k<n-1; k=k+2)


s=s+h*(y[k]+4*y[k+1]+y[k+2])/3;
return s;

double integ_func(double a, double b, double eps)


//
{
double n=2;
double h=(b-a)/n;
double s=(f(a)+4*f((a+b)/2)+f(b))*h/3;
double s1,c,x;
do{

n=2*n;
h=(b-a)/n;
s1=s;
c=4;
x=a;
s=f(a)+f(b);
for(int k=1; k<n; k++)
{
x=x+h;
s=s+c*f(x);
c=6-c;
}
s=s*h/3;
}while(fabs(s-s1)/15>=eps);
return s;
}


-
y = x
[0;1] x0 = 0, y 0 = 0.
, y =
:
x
0 0.1
0.2
0.3
y(x) 0 0.005 0.02 0.045

0.4
0.08

0.5
0.125

x2
,
2

0.6
0.18

0.7
0.245

0.8
0.32

0.9
0.405

1
0.5

, , .

,
( f ( x) = x 2 + 3x 4 ):
x
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
y(x)
-4
-3.69 -3.36 -3.01 -2.64 -2.25 -1.84 -1.41 -0.96 -0.49 0
:

, , .


3

2
I := 3x dx

, I=26.
:

I=26, , , .

.
double Sum_x(double* x_arr, int n)
{
double s=0;
for(int i=0;i<n;i++)
s=s+x_arr[i];
return s;
}
double Sum_x2(double* x_arr, int n)
{
double s=0;
for(int i=0;i<n;i++)
s=s+pow(x_arr[i],2.);
return s;
}
double Sum_x3(double* x_arr, int n)
{
double s=0;
for(int i=0;i<n;i++)
s=s+pow(x_arr[i],3.);
return s;
}
double Sum_x4(double* x_arr, int n)
{
double s=0;
for(int i=0;i<n;i++)
s=s+pow(x_arr[i],4.);
return s;
}
double Sum_xy(double* x_arr, double* y_arr, int n)
{
double s=0;
for(int i=0;i<n;i++)
s=s+x_arr[i]*y_arr[i];
return s;
}
double Sum_x2y(double* x_arr, double* y_arr, int n)
{
double s=0;
for(int i=0;i<n;i++)
s=s+pow(x_arr[i],2.)*y_arr[i];
return s;
}

10

.
double f_main(double& a, double& b, double& h, double& y0, double& eps,
double* x_arr, double* y_arr, double& int1, double& int2)
{
double* b_arr;
double** a_arr;
int n=((b-a)/h)/1+1; //
ODU(a,y0,h,eps,b,x_arr, y_arr); //
//
b_arr=new double[3];
b_arr[0]=Sum_x(y_arr,n);
b_arr[1]=Sum_xy(x_arr, y_arr, n);
b_arr[2]=Sum_x2y(x_arr,y_arr,n);
a_arr=new double*[3];
a_arr[0]=new double[3];
a_arr[0][0]=n;
a_arr[0][1]=Sum_x(x_arr,n);
a_arr[0][2]=Sum_x2(x_arr,n);
a_arr[1]=new double[3];
a_arr[1][0]=Sum_x(x_arr,n);
a_arr[1][1]=Sum_x2(x_arr,n);
a_arr[1][2]=Sum_x3(x_arr,n);
a_arr[2]=new double[3];
a_arr[2][0]=Sum_x2(x_arr,n);
a_arr[2][1]=Sum_x3(x_arr,n);
a_arr[2][2]=Sum_x4(x_arr,n);
approximation(a_arr,b_arr); //
int1=integ_point(a,b,eps,y_arr);//

int2=integ_func(a,b,eps);//

double r=int1-int2;
return r; //
}

11

12

.
:
h := 0.1
n := 10

f ( x, y ) :=

x+

i := 1 .. n

x0
: = 0
y 0 0

k1( x, y ) := h f ( x, y )
k2( x, y ) := h f x +

k3( x, y ) := h f x +

,y +

k1( x, y)

,y +

k2( x, y )

k4( x, y ) := h f ( x + h , y + k3( x, y ) )
k ( x, y ) := k1( x, y ) + 2 k2( x, y ) + 2 k3( x, y ) + k4( x, y )

x + h

i 1
xi

:=
k( x , y )
i 1 i 1
y i y +

1
6

x =

y =

i := 0 .. n

0.1

0.027

0.2

0.088

0.3

0.174

0.4

0.281

0.5

0.406

0.6

0.549

0.7

0.709

0.8

0.885

0.9

1.076

1.282

13

:
0
0.1


0.2
0.3
0.4

X := 0.5
0.6

0.7
0.8
0.9

1

0
0.03080

0.09348
0.17987
0.28696

Y := 0.41289
0.55641

0.71657
0.89266
1.08406

1.29033

i := 0 .. 10

f2( x) := x
x2

0.0116
s = 0.3818

0.9278

s := linfit( X , Y, f2)

L2( x) := 0.9278x
+ 0.3818x
0.0116

:
a := 0

b := 1

1. , ,
h := 0.1

n :=

b a
h

= 10

i := 0 .. n

m := 1 , 3 .. n 1
k := 2 , 4 .. n 2

Ic1 :=

h y + y + 4 y + 2 y = 0.488204
0 10
m
k

m
k

2. ,
Ic2 :=

h f x + f x + 4 f x + 2
3 ( 0)
( 10) ( m)

f ( xk ) = 0.488567
k

R1 := Ic1 Ic2 = 3.63 10

14

.
1.
,
,

,
.
2.
,
.
- ,
,
.
.
,
.
3.
0.4887,
- 0.48904. 0.00034.
=0.0001
4.
.
, .

15

- 4-

- 4-

10

11

12

13

15

16

17

16

:
1) .. . ( )
2) .., .., ..
( ) . - ., , 2003, -72.
3) .., .. . Mathcad
- .: , 2006, -121.

17

Оценить