Documente Academic
Documente Profesional
Documente Cultură
INTEGRAREA FUNC
TIILOR
11.1 Introducere
Daca pt. f (x) continua pe [a, b] este cunoscuta primitiva F (x) formula Newton-Leibnitz:
I=
i=1
f (x)dx.
xi = a + (i 1)h,
i = 1, 2, . . . , n
h = (b a)/(n 1).
Aproximam functia f (x) prin polinomul de interpolare Lagrange (fi f (xi )):
n Qn
X
(x xj )
Qnj6=i
Pn1 (x) =
fi .
j6=i (xi xj )
i=1
Definim variabila adimensionala:
q = (x a)/h,
q [0, n 1].
j6=i
n
Y
j6=i
n1
(xi xj ) = h
n
i1
n
Y
Y
Y
ni n1
(i j) = (1) h
(i j)
(j i) = (1)ni hn1 (i 1)!(n i)!
j=1
j6=i
Polinomul Lagrange:
Pn1 (x) =
n
X
i=1
Aproximatie a integralei:
Z
f (x)dx
Ai =
Qn
j=i+1
Qn
j6=i [q (j 1)]
(1)ni (i 1)!(n i)!
Pn1 (x)dx =
n
X
fi
Ai fi ,
i=1
j6=i [q (j 1)]dx
(1)ni (i 1)!(n i)!
R n1 Qn
j6=i [q (j 1)]dq
.
(1)ni (i 1)!(n i)!
0
a Newton-Cotes:
Punem Ai = (b a)Hi formula de cuadratur
Z b
n
X
f (x)dx (b a)
Hi fi ,
a
Coeficientii Cotes:
Hi =
Proprietati:
i=1
R n1 Qn
(j 1)]dq
,
(1)ni (i 1)!(n i)!(n 1)
0
j6=i [q
n
X
Hi = 1,
i = 1, 2, . . . , n.
Hi = Hni+1 .
i=1
Formula trapezului:
1
(q 1)dq = ,
2
x2
x1
f (x)dx
H2 =
1
qdq = .
2
h
(f1 + f2 ).
2
y
y = f(x)
y = P1(x)
f2
f1
h
x1
x2
FIGURA 11.1. Formula trapezului aproximeaza functia prin dreapta care trece prin punctele
(x1 , f1 ) si (x2 , f2 ).
h3 00
f (),
12
3
(x1 , x2 ).
fi
fn
f1
h
x1 x2 x3
h
xi
xn x
FIGURA 11.2. Formula trapezelor aproximeaza integrandul cu linia poligonala definita de abscisele echidistante si valorile corespunzatoare ale functiei.
i = 1, 2, . . . , n.
h = (b a)/(n 1)
Aplicam formula trapezului fiecarui subinterval [x1 , x2 ],..., [xn1 , xn ]:
Z b
h
h
h
f (x)dx (f1 + f2 ) + (f2 + f3 ) + . . . + (fn1 + fn ).
2
2
2
a
Formula trapezelor:
Z
Restul:
R=
#
n1
f1 X
fn
+
.
f (x)dx h
fi +
2
2
i=2
"
(n 1)h3 00
(b a)h2 00
f () =
f (),
12
12
[a, b].
/*=========================================================================*/
float Trapez(float Func(float), float a, float b, int n)
/*--------------------------------------------------------------------------Calculeaza integrala functiei Func pe intervalul [a,b] utilizand formula
trapezelor cu n puncte de integrare
---------------------------------------------------------------------------*/
{
float h, s;
int i;
h = (b-a)/(n-1);
s = 0.5*(Func(a) + Func(b));
for (i=1; i<=(n-2); i++) s += Func(a+i*h);
return h*s;
}
n0 =1
h0
h1
n1 =2
h2
n2 =4
n3 =8
h3
f (a) f (b)
+
, h0 = b a
T0 = h0
2
2
f (a)
f (b)
T1 = h1
+ f (a + h1 ) +
, h1 = h0 /2
2
2
f (a)
f (b)
T2 = h2
+ f (a + h2 ) + f (a + 2h2 ) + f (a + 3h2 ) +
,
2
2
h2 = h1 /2
Proces recurent:
h0
[f (a) + f (b)], h0 = b a, n0 = 1
2"
#
nk1
X
1
Tk1 + hk1
=
f (a + (i 1/2)hk1 ) ,
2
i=1
T0 =
Tk
hk = hk1 /2,
nk = 2nk1 ,
k = 1, 2, . . .
/*=========================================================================*/
float TrapezControl(float Func(float), float a, float b)
/*--------------------------------------------------------------------------Calculeaza integrala functiei Func pe intervalul [a,b] utilizand formula
trapezelor cu controlul automat al pasului de integrare
---------------------------------------------------------------------------*/
{
const float eps = 1e-6;
/* precizia relativa a integralei */
const int kmax = 30;
/* numar maxim de injumatatiri */
float h, sum, t, t0;
long i, n;
int k;
h = b-a; n = 1;
t0 = 0.5*h*(Func(a) + Func(b));
/* aproximatie initiala */
1
=
4
1
(q 1)(q 2)dq = ,
6
0
Z 2
1
2
=
q(q 2)dq = ,
2
3
Z 20
1
1
=
q(q 1)dq = .
4 0
6
h5 (4)
f (),
90
[a, b]
i = 1, 2, . . . , n,
ba
ba
=
,
n1
2m
Aplicam formula trapezului fiecarui subinterval [x1 , x2 ],..., [xn1 , xn ]:
Z b
h
h
h
f (x)dx (f1 + 4f2 + f3 ) + (f3 + 4f4 + f5 ) + . . . + (fn2 + 4fn1 + fn ).
3
3
3
a
h=
1 =
(n1)/2
f2i+1 ,
i=1
2 =
f2i .
i=1
(b a)h4 (4)
mh5 (4)
f () =
f (),
90
180
8
[a, b].
/*=========================================================================*/
float Simpson0(float Func(float), float a, float b, int n)
/*--------------------------------------------------------------------------Calculeaza integrala functiei Func pe intervalul [a,b] utilizand formula lui
Simpson cu n puncte de integrare
---------------------------------------------------------------------------*/
{
float h, s1, s2;
int i, par = 0;
if ((n/2)*2 == n) n++;
h = (b-a)/(n-1);
s1 = s2 = 0.0;
for (i=1; i<=(n-2); i++) {
if (par) s1 += Func(a+i*h); else s2 += Func(a+i*h);
par = ~par;
/* paritatea urmatorului termen */
}
return (h/3)*(Func(a) + 4*s2 + 2*s1 + Func(b));
}
1 =
f (x2i+1 ),
x2i+1 = a + i(2h)
i=1
2 = f (x2 ) +
(n3)/2
f (x2(i+1) ),
x2(i+1) = x2i+1 + h,
i=1
/*=========================================================================*/
float Simpson(float Func(float), float a, float b, int n)
/*--------------------------------------------------------------------------Calculeaza integrala functiei Func pe intervalul [a,b] utilizand formula lui
Simpson cu n puncte de integrare
---------------------------------------------------------------------------*/
{
float h, h2, s1, s2, x;
int i;
if ((n/2)*2 == n) n++;
h = (b-a)/(n-1); h2 = 2*h;
s1 = 0.0; s2 = Func(a+h);
for (i=1; i<=(n-3)/2; i++) {
x = a + i*h2;
s1 += Func(x); s2 += Func(x+h);
}
return (h/3)*(Func(a) + 4*s2 + 2*s1 + Func(b));
}
S1 =
Generaliznd:
Sk =
4Tk Tk1
.
3
Proces recurent:
h0
[f (a) + f (b)], h0 = b a, n0 = 1
2"
#
nk1
X
1
Tk1 + hk1
f (a + (i 1/2)hk1 ) ,
Tk =
2
i=1
T0 =
Sk =
4Tk Tk1
,
3
hk = hk1 /2,
k = 1, 2, . . .
nk = 2nk1 .
Criteriu de convergenta
:
|Sk Sk1 | |Sk | .
/*=========================================================================*/
float SimpsonControl(float Func(float), float a, float b)
/*--------------------------------------------------------------------------Calculeaza integrala functiei Func pe intervalul [a,b] utilizand formula lui
Simpson cu controlul automat al pasului de integrare
---------------------------------------------------------------------------*/
{
const float eps = 1e-6;
/* precizia relativa a integralei */
const int kmax = 30;
/* numar maxim de injumatatiri */
float h, s, s0, sum, t, t0;
long i, n;
int k;
h = b-a; n = 1;
s0 = t0 = 0.5*h*(Func(a) + Func(b));
/* aproximatie initiala */
10
ymin (x)
xmax
Fx (x)dx,
Fx (x) =
ymax (x)
f (x, y)dy,
ymin (x)
xmin
ymin(xi)
xmin
xi
xmax
ymax (xi )
f (xi , y)dy
ymin (xi )
Exemplu:
1x2
1 x2 y 2 dy = 0.523599.
6
0
0
Domeniul de integrare primul cadran al cercului de raza 1.
Rezultatul volumul primului octant al sferei de raza 1.
I=
dx
#include <stdio.h>
#include <math.h>
float xconst;
/*=========================================================================*/
float func(float x, float y)
{
return sqrt(fabs(1. - x*x - y*y));
}
/*=========================================================================*/
float ymin(float x) { return 0.0; }
/*=========================================================================*/
float ymax(float x) { return sqrt(1. - x*x); }
/*=========================================================================*/
float SimpsonControl(float Func(float), float a, float b)
{
. . . . . . . . . .
}
/*=========================================================================*/
float Fy(float y)
/* functie interfata de o variabila */
{
/* pt. functia utilizator func(x,y) */
return func(xconst,y);
/* xconst este variabila globala */
}
/*=========================================================================*/
float Fx(float x)
{
xconst = x;
return SimpsonControl(Fy,ymin(x),ymax(x));
}
/*=========================================================================*/
void main()
{
float xmin = 0.0, xmax = 1.0;
printf("Integrala = %f\n",SimpsonControl(Fx,xmin,xmax));
}
xmax
xmin
ymax (x)
zmax (x,y)
f (x, y, z)dxdydz =
ymin (x)
zmin (x,y)
Z ymax (x)
Fx (x) =
Fy (x, y)dy,
Fy (x, y) =
ymin (x)
xmax
zmin (x,y)
12
Fx (x)dx,
xmin
zmax (x,y)
f (x, y, z)dz.
Exemplu:
I=
dx
1x2
dy
Z 1x2 y2
0
dz =
0.523599,
6
#include <stdio.h>
#include <math.h>
float xconst, yconst;
/*=========================================================================*/
float func(float x, float y, float z)
{
return 1.0;
}
/*=========================================================================*/
float ymin(float x) { return 0.0; }
/*=========================================================================*/
float ymax(float x) { return sqrt(1. - x*x); }
/*=========================================================================*/
float zmin(float x, float y) { return 0.0; }
/*=========================================================================*/
float zmax(float x, float y) { return sqrt(fabs(1. - x*x - y*y)); }
/*=========================================================================*/
float SimpsonControl(float Func(float), float a, float b)
{
. . . . . . . . . .
}
/*=========================================================================*/
float Fz(float z)
/* functie interfata de o variabila
*/
{
/* pt. functia utilizator func(x,y,z) */
return func(xconst,yconst,z);
/* xconst, yconst - variabile globale */
}
/*=========================================================================*/
float Fy(float y)
{
yconst = y;
return SimpsonControl(Fz,zmin(xconst,y),zmax(xconst,y));
}
/*=========================================================================*/
float Fx(float x)
{
xconst = x;
return SimpsonControl(Fy,ymin(x),ymax(x));
}
/*=========================================================================*/
void main()
{
float xmin = 0.0, xmax = 1.0;
printf("Integrala = %f\n",SimpsonControl(Fx,xmin,xmax));
}
Bibliography
[1] M. Abramowitz si I. Stegun, Handbook of Mathematical Functions (Dover Publications, New York, 1972).
[2] A.H. Stroud si D. Secrest, Gaussian Cuadrature Formulas (Prentice-Hall, Englewood
Clis, 1966).
[3] A.H. Stroud, Approximate Calculation of Multiple Integrals (Prentice-Hall, Englewood
Clis, 1971).
[4] A. Ralston si P. Rabinowitz, A First Course in Numerical Analysis (McGraw-Hill,
New York, 1978).
[5] B.P. Demidovich si I.A. Maron, Computational Mathematics (MIR Publishers,
Moskow, 1981).
[6] R.L. Burden si J.D. Faires, Numerical Analysis, Third Edition (Prindle, Weber &
Schmidt, Boston, 1985).
[7] W.H. Press, S.A. Teukolsky, W.T. Vetterling si B.P. Flannery, Numerical Recipes in
C: The Art of Scientific Computing, Second Edition (Cambridge University Press,
Cambridge, 1992).