You are on page 1of 49

CHNG 6: O HM V TCH PHN S

1.TNHOHMBCNHTBNGPHNGPHPROMBERG
o hm theo phng php Romberg l mt phng php ngoi suy
xcnhohmvimtchnhxccao.TaxtkhaitrinTaylorca
hmf(x)ti(x+h)v(xh):
h2
h3
h4
f( x + h) = f( x) + hf ( x) + f ( x) + f ( x) + f ( 4 ) ( x) +
(1)
2
3!
4!
h2
h3
h4 (4)

f( x h) = f( x) hf ( x) + f ( x) f ( x) + f ( x)
(2)
2
3!
4!
Tr(1)cho(2)tac:
2h 3
2h 5 ( 5)

f( x + h ) f( x h) = 2 hf ( x) +
f ( x) +
f ( x) +

(3)
3!
5!
Nhvyrtra:
h4
f( x + h) f( x h) h 2
f ( x) =
f ( x) f ( 5 ) ( x)

(4)
2h
3!
5!
haytacthvitli:
1
[f( x + h) f( x h)] + a 2 h 2 + a 4 h 4 + a 6 h 6 +
f ( x) =

(5)
2h
trongcchsaiphthucfvx.
Tat:
1

(6)
[f( x + h) f( x h)]
( h) =
2h
Nhvyt(5)v(6)tac:
D(1,1) = ( h) = f ( x) a 2 h 2 a 4 h 4 a 6 h 6

(7)

h6
h4
h2
h

(8)
a4
a6

D( 2 ,1) = = f ( x) a 2
64
16
4
2
vtngqutvihi=h/2i1tac:
D(i ,1) = ( h i ) = f ( x) a 2 h i2 a 4 h i4 a 6 h 6i

(9)
TatorasaiphnD(1,1)4D(2,1)vc:
h
3
15
( h) 4 = 3f ( x) a 4 h 4 a 6 h 6

(10)
4
16
2
Chiahaivca(10)cho3tanhnc:
4 D( 2 ,1) D(1,1)
1
5
D( 2 ,2) =
= f ( x) + a 4 h 4 + a 6 h 6 +

(11)
4
4
16
TrongkhiD(1,1)vD(2,1)saikhcf(x)phthucvoh2thD(2,2)saikhc
f(x)phthucvoh4.Bygitalichiaibchvnhnc:
311

1
h
5
h
D( 3 ,2) = f ( x) + a 4 + a 6 +

(12)

4 2 16 2
vkhshngch4bngcchtora:
15
D( 2 ,3) 16 D( 3,2) = 15f ( x) + + a 6 h 6

(13)

64
Chiahaivca(13)cho15tac:
16 D( 3,2) D( 2 ,2)
1

(14)
D( 3 ,3) =
= f ( x) a 6 h 6
15
64
Vilntnhnysaiscaohmchcnphthucvoh6.Litiptcchia
i bc h v tnh D(4, 4) th sai s ph thuc h8. S tnh o hm theo
phngphpRombergl:

D(1,1)

D(2,1)

D(2,2)

D(3,1)

D(3,2)

D(3,3)

D(4,2)

D(4,3)

D(4,4)

D(4,1)

............
trongmigitrsaulgitrngoisuycagitrtrchngtrn.
Vi2jintac:
4 j1 D(i , j 1) D(i 1, j 1)

D(i , j) =
4 j1 1
vgitrkhiul:
1
[f( x + h i ) f( x h i )]

D(i , j) = ( h i ) =
2h i

vihi=h/2i1.
Chngtangnglikhihiugiahailnngoisuytchnhxcyu
cu.
Taxydnghmdiffromberg()thchinthuttontrn:

functiondf=diffromberg(f,x,h,maxiter,tol)
%TinhdaohambangphuongphapRomberg
D(1,1)=(feval(f,x+h)feval(f,xh))/(2*h);
fori=1:maxiter
h=h/2;
D(i+1,1)=(feval(f,x+h)feval(f,xh))/(2*h);
forj=1:i
D(i+1,j+1)=(4^j*D(i+1,j)D(i,j))/(4^j1);
312

end
if(abs(D(i+1,i+1)D(i,i))<tol)
df=D(i+1,i+1);
break;
elseif(i==maxiter)
error(NgoaisuyRichardsonkhonghoitu);
end
end

tnhohmcahmchotrctadngchngtrnhctdiffromberg.m:

clearall,clc
formatlong;
f=inline(x^2+2*x*exp(x)+1);
x=2;
h=0.5;
tol=1e6;
maxiter=10;
df=diffromberg(f,x,h,maxiter,tol)

2.TNHOHMBCCAO

TaxtkhaitrinTaylorcahmf(x):
h2
h3
h4
f( x + h) = f( x) + hf ( x) + f ( x) + f ( x) + f ( 4 ) ( x) +
(1)
2
3!
4!
h2
h3
h 4 (4)

f(x h) = f(x) hf (x) +


f (x)
f (x) +
f (x)
(2)
2
3!
4!
T(1)v(2)tac:
f(x + h) 2f(x) + f(x h)
D(2)
c2 (x, h) =
h2

(3)

h 2 (4)
2h 4 (6)
= f (x) +
f (x) +
f (x) + L
12
6!
Nh vy nu ta tnh o hm cp 2 theo (3) th sai s c h2. Dng phng
phpngoisuyRichadsontac:

313

(2)
2 2 D(2)
f(x + 2h) + 16f(x + h) 30f(x) + 16f(x + h) f(x 2h)
c2 (x, h) D c2 (x, 2h)
=
22 1
12h 2

h 4 ( 5)
f (x) +L
= f (x)
90
Dovy:
f(x + 2h) + 16f(x + h) 30f(x) + 16f(x + h) f(x 2h)
D(2)
c2 (x, h) =
12h 2

(4)
h 4 ( 5)
f (x) +L
= f (x)
90
Nuohmcpctnhtheo(4)thsaischcnch4.T(4)tac:
c 2 f2 + c1f1 + c 0 f0 + c 1f1 + c 2 f2
D(2)

(5)

c2 (x, h) =
h2
Trong:

f2=f(x+2h)

f1=f(x+h)

f0=f(x)

f1=f(xh)
f2=f(x2h)
VitrcckhaitrinTaylorcaf2,f1,f0,f1,f2tac:

(2h)2
h2

c
f
2hf
f
c
f
hf
f
+
+
+
+
+
+
+
L
L
20

0
0
1
0
0
0

2!
2!
1

(2)
Dc2 (x, h) = 2

h2
( 2h)2
f0 L + c 2 f0 2hf0 +
f0 L
+c f + c 1 f0 hf0 +
00
2!
2!

(c 2 + c1 + c 0 + c 1 + c 2)f0 + h(2c 2 + c1 + c 1 2c 2 )f0


1

2
D(2)

1
1
22
(6)
c2 (x, h) =
2 2
2
h + h c 2 + c1 + c 1 + c 2 f0 + L

2
2
2
2

Taphigiihphngtrnhsautmcchsci.
1 1
1
1 c 2 0
1
2
1
2 c 1 0
1 0
2

2 2 2! c 0 = 1
2 2! 1 2! 0 1 2!

(7)

3
2 3! 1 3! 0 1 3! 2 3! c 1 0
2 4 4! 1 4! 0 1 4! 2 4 4! c 2 0

314

Ktqutacc2=1/12,c1=4/3,c0=5/2,c1=4/3c2=1/12.Dovy:
f2 + 16f1 30f0 + 16f1 f2
D(2)

c2 (x, h) =
12h 2
Tngttacohmbc4cahm:
f2 4f1 + 6f0 4f1 + f2
D(4)
(x,
h)
=

c2
12h 4
Taxydnghmdiffn()tnhohmtibc5:

functiondf=diffn(f,n,x)
%Tinhdaohamcapncuaftaix
ifn>5
error(Hamchitinhduocdaohamdenbac5);
return;
end;
N=5;
xo=x;
T(1)=feval(f,xo);
h=0.005;
tmp=1;
fori=1:N
tmp=tmp*h;
c=difapx(i,[ii]);%hesocuadaoham
dix=c*feval(f,xo+[i:i]*h);
T(i+1)=dix/tmp;%daoham
end
df=T(n+1);
h=0.005;
tmp=1;
fori=1:N
tmp=tmp*h;
c=difapx(i,[ii]);%hesocuadaoham
dix=c*feval(f,xo+[i:i]*h);%/h^i;%daoham
T(i+1)=dix/tmp;%hesocuachuoiTaylor
end
df=T(n+1);

315

tnhohmcahmtadngchngtrnhctdiffn.m

clearall,clc
f=inline(x.^2+atan(x),x);
df=diffn(f,5,0)

3.TNHOHMBNGPHNGPHPNISUY

Gistachmchodidngbng:

x
x0
x1
x0
...
xn
y
y0
y1
y0
...
yn

tmohmcahmtimtimnotasnisuyhmrisau
tnhohmcahmtiimcho.Taxydnghm diffinterp()thc
hincngvictrn.

functiondf=diffinterp(x,y,n,x0)
%Tinhdaohamcap1hai2bangphuogphapnoisuy
px=lagrange(x,y);%TimdathucnoisuyLagrange(x,y)
[p,dp,ddp]=peval(px,x0);
fprintf(Trisocuahamla:%f\n,p)
ifn==1
df=dp;
else
df=ddp;
end
fprintf(Daohamcap%dla:%f\n,n,df);

tnhohmtadngchngtrnhctdiffinterp.m:

clear,clc
x0=pi/4;
x=[2:6]*pi/16;
y=sin(x);
x=[1.51.92.12.63.2];
y=[1.06281.39611.54321.84232.0397];
316

n=2;
df=diffinterp(x,y,n,x0);

4.TCHPHNXCNH
Mc ch ca tnh tch phn xc nh, cn gi l cu phng, l nh
ginhlngbiuthc:
y
b
B
J = f( x)dx
a

trong f(x) l hm lin tc trong khong


[a,b]vcthbiudinbingcongy=
f(x). Nh vy tch phn xc nh J l din
tchSABba,giihnbingcongf(x),trc
honh,ccngthngx=avx=b.Tch
phn ny thng c tnh gn ng bng
cngthc:

J = A i f(xi )
i =1

trongAiltrngs,phthucphngphptnhtchphn.
Ttcccphngphptnhtchphncsuyratphngphpni
suyhmdidutchphn.Dovyktquschnhxcnuhmcthxp
xbngathc.Ccphngphptnhtchphnxcnhbngphngphp
scchiathnh2nhm:ccphngphpNewtonCotesvccphng
phpGauss.KhidngccphngphpNewtonCoteskhonglytchphn
c chia u nh trong phng php hnh thang hay phng php
Simpson.KhidngccphngphpGauss,cccdimchiacchnt
chnhxccaonht.Dophngphpnycntlntnhgitrhmdci
dutchphnnnthchhpkhihmf(x)khtnh.

5.CCCNGTHCNEWTONCOTES
1.Khinimchung:Takhosttchphn
b

J= f(x)dx

(1)

Tachiaminlytchphn[a,b]thnh(n1)onbngnhauc
chiudimionh=(ba)/(n1)nhhnhvvkhiuccimchial

317

x1,x2,..,xn.Sautaxpxhmf(x)bnga
thc bc (n 1) i qua cc nt. a thc ni
suyLagrangecaf(x)cdng:
n

Pn 1 (x) = f(xi )Li (x)


i =1

Nhvy,xpxtchphn(1)l:
b

J= f(x)dx = Pn1 (x)dx =


a

x1

i =1

i =1

xn

x2 x3

f(x ) L (x)dx = A f(x )


b

(2)

(3)

Trong:
b

A i = Li (x)dx

i = 1,2,...,n

Cng thc (2) l cng thc Newton Cotes. Vi n = 2 ta c cng thc hnh
thangvvin=3taccngthcSimpson.
2.Phngphphnhthang:Khin=2tac:
x x2
xb

L1 (x) =
=
x1 x 2
h
x x1 x a

L 2 (x) =
=
h
x 2 x1
h
b

1
1
h
A1 =
(x b)dx =
(b a)2 =
h
2h
2

x1=a

x2=b

A2 =

1
1
h
(x a)dx =
(b a)2 =
h
2h
2
a

Vy:
h
J = f(a) + f(b)

2
Trongthct,phngphphnhthangcpdngtrntngon.Trn
mion[xi,xi+1]tac:
h

J i = f(x i ) + f(xi+1 )

2
n
h
(7)
v: J = J i = f(x1 ) + 2f(x 2 ) + 2f(x 3 ) + L + 2f(x n 1 ) + 2f(x n )

2
i =1

TagiH=ba.Nutchphntrnctnhchbikhnhthangth:
H

k=1:
J1 = f(a) + f(b)

(8)

318

k=2:

k=3:

H 1
H
H H

J 2 = f(a) + 2f a + + f(b) = J1 + f a +
2
22

4 2

H
H
H
3H

J 2 = f(a) + 2f a + + 2f a + + 2f a +
f(b)
+

4
2
4

H
3H H
1
= J 2 + f a + + f a +

4
4 4
2

Tngqut,vik>1tac:
2 k 1

Jk =

1
H
J k1 + k1
2
2

i =1

f a +

(2i 1)H
2 k1

k = 2,3,...

(9)

Cngthc(8)lcngthchnhthanglp.Tathyrngtngchchaccnt
mixuthinkhishnhthangtnggpi.TnhdyJ1,J2,...bng(8)v(9)
cncngmtslntnhnhkhidng(7).Nhngkhidng(8)v(9)takim
tractnhhitvcthdnglpkhitchnhxcchotrc.
Taxydnghmtrapezoid()thchinthuttontrn.

functionJ=trapezoid(f,a,b,maxiter,tol)
%Quytachinhthanglap.
%Cuphap:J=trapezoid(f,a,b,k)

fa=feval(f,a);
fb=feval(f,b);
J1=(fa+fb)*(ba)/2;
fork=2:maxiter
n=2^(k2);%sodiemmoi
h=(ba)/n;%khoangchiamoi
x=a+h/2.0;%toadodiemmoithunhat
sum=0.0;
fori=1:n
fx=feval(f,x);
sum=sum+fx;
x=x+h;
end
319

J=(J1+h*sum)/2;
ifabs(J1J)<tol
break;
end
J1=J;
end

tnhtchphntadngchngtrnhcttrapezoid.m
clearall,clc
f=inline((x^3+1)*sin(x),x);
a=0;
b=1;
maxiter=50;
tol=1e6;
J=trapezoid(f,a,b,maxiter,tol)
3.PhngphpSimpson:Khin=3taccngthc
Simpson.Qua3im,hmf(x)cxpxbngmt
hm bc hai(mt parabol). tnh tch phn ta thay
hmf(x)vphibngathcnisuyNewtontin
bc2:
t(t 1) 2
P2 = y 0 + ty 0 +
y0

(10)

2!
vtac:
b

x0=a x1 x2=b

f(x)dx = P (x)dx
2

(11)

ibinx=x1+ththdx=hdt.Vix=x1tht=0vvix=x3tht=2nn:

320

P (x)dx = h y
2

+ ty 0 +

t(t 1) 2
y 0 dt
2!

t =2

t2
1 t3 t2 2
= h y 0 t + y 0 + y 0
2
2 3 2

t =0
1 8 4

= h 2y 0 + 2y 0 + 2 y 0
2 3 2

(12)

h
h
a+b

( y0 + 4y1 + y 2 ) = f(a) + 4f
+ f(b)
3
3
2

Thcttachiaon[a,b]thnh2nphnvtnhtchphntrnmioncon.
Cngcctchphntrncconcontac:
b
h

a f(x)dx = 3 y0 + 4 ( y1 + y3 + + y2n1 ) + 2 ( y2 + y4 + + y2n2 ) + y 2n (13)


=

Cngthc(13)ihinlschn.
Taxydnghmsimpson()thchinthuttontrn

functions=simpson(f,a,b,n)
%nsokhoangchia
%neufchuatrongmotfiledungkihieu@degoi
%s=simpson(@f,a,b,n).
%neuflahaminline
%s=simpson(f,a,b,n).
ifmod(n,2)~=0
n=n+1
end
h=(ba)/(2*n);
s1=0;
s2=0;
fork=1:n
x=a+h*(2*k1);
s1=s1+f(x);
end
fork=1:(n1)
x=a+h*2*k;
s2=s2+f(x);
321

end
s=h*(f(a)+f(b)+4*s1+2*s2)/3;
clc

tnhtchphntadngchngtrnhctsimpson.m:
clearall,clc
f=inline(exp(x).*sin(x),x);
a=0;
b=1;
n=6;
s=simpson(f,a,b,n)

3.Phngphpcuphngthchnghi:Trong
tch phn bng phng php Simpson, cc
on c chia u v lm cho sai s khng
ging nhau trn cc on: sai s ln trn cc
onhmbininhiuvsaisnhtrncc
onhmtngibngphng.Ngcli
phngphpcuphngthchnghichiacconkhngu:ngntrncc
onhmthayinhiuvditrncconthayitvscsaisnh
khisonchianh.

Thuttoncuphngthchnghibtubngvictnhtchphnint
ivitonbon[a,b]vtngtchphnint12=int1+int2trn2on
bngnhau.Datrnintvint12tatnhsais.Nuchatchnhxc,ta
chiaimionvlpliqutrnhtnh.Tadnghm adaptivesimpson()
thchinthuttonny:

functionint=adaptivesimpson(f,a,b,tol)
mid=(b+a)/2.0;
int=simpsonapprox(f,a,b);
int12=simpsonapprox(f,a,mid)+simpsonapprox(f,mid,b);
if(abs(intint12)<15.0*tol)
int=int12;
else
leftint=adaptivesimpson(f,a,mid,tol/2);
rightint=adaptivesimpson(f,mid,b,tol/2);
322

int=leftint+rightint;
end

functionint=simpsonapprox(f,a,b)
h=(ba)/2.0;
int=h*(feval(f,a)+4.0*feval(f,(a+h))+feval(f,b))/3.0;

tnhtchphntadngchngtrnhctadaptive.m:

clc,clearall
f=inline(sqrt(x).*cos(x));
a=0;
b=1;
tol=1e5;
J=adaptivesimpson(f,a,b,tol)

6.TCHPHNROMBERG

TchphnRombergkthpquytctchphnhnhthangviphng
phpngoisuyRichardson.Trchttaavokhinim:

Ri,1=Ji
b

TrongJilgitrxpxca f(x)dx ccbngcchtnhtheoquytc


a

lphnhthanglnthi.

TchphnRombergbtutR1,1=J1(mthnhthang)vR2,1=J2 (hai
hnthang).SautnhR2,2bngcchngoisuy:
2 2 R 2 ,1 R 1,1 4
1
R 2 ,2 =
= R 2 ,1 R 1,1

(1)

2
2 1
3
3
tindngtaluccktquvomngdng:
R 1,1

R
2 ,2
2 ,1
BctiptheoltnhR3,1=J3(bnhnhthang)vlplingoisuyRichadson
tac:
2 2 R 3,1 R 2 ,1 4
1
R 3,2 =
= R 3,1 R 2 ,1

(2)

2
2 1
3
3

323

2 4 R 3,2 R 2 ,2 16
1
=
R

R 2 ,2
v: R 3,3 =
3,2
24 1
15
15
CcphntcaRbygigm:
R 1,1

R 2 ,1 R 2 ,2

R 3,1 R 3,2 R 3,3

Cngthctngqutdngtrongsnyl:
4 j1 R i ,j1 R i1,j1

R i ,j =
i > 1, j = 2, 3,...

4 j1 1
Taxydnghmromberg()thchinthuttontrn:

functionJ=romberg(f,a,b,maxiter,tol)
m=1;
h=ba;
err=1;
j=0;
R=zeros(4,4);
R(1,1)=h*(f(a)+f(b))/2;
while((err>tol)&(j<maxiter))|(j<4)
j=j+1;
h=h/2;
s=0;
forp=1:m
x=a+h*(2*p1);
s=s+f(x);
end
R(j+1,1)=R(j,1)/2+h*s;
m=2*m;
fork=1:j
R(j+1,k+1)=R(j+1,k)+(R(j+1,k)R(j,k))/(4^k1);
end
err=abs(R(j,j)R(j+1,k+1));
end
J=R(j+1,j+1);

(3)

(4)

324

tnhtchphntadngchngtrnhctromberg.m:

clearall,clc
f=inline(exp(x).*sin(x),x);
a=0;
b=1;
maxiter=20;
tol=1e6;
J=romberg(f,a,b,maxiter,tol)

7.TCHPHNBOOL

Takhosthmy=f(x)trnon[x0,x4],vi:
x1=x0+h,x2=x0+2h,x3=x0+3h,x4=x0+4h
TheoBool,tchphn:
x4
2h m

J = f(x)dx =
7f(x0 ) + 32f(x1 ) + 12f(x 2 ) + 32f(x 3 ) + 7f(x 4 )

45
k
1
=
x0
Xttchphn:
b

J = f(x)dx
a

ba
bicc
4m
imchiaxk=x0+hk=a+hk,k=0,1,...,4m.CngthcBoolcho4mon
conl:
b
2h m
7f(x0 ) + 32f(x1 ) + 12f(x 2 ) + 32f(x 3 ) + 7f(x 4 )

J = f(x)dx =

45
k =1
a
Tachiaon[a,b]thnh4monconunhaucrng h =

Taxydnghmintbool()thchinthuttonny

functiontp=intbool(f,a,b,m)
%TinhtichphanbangphuongphapBool
a=0;
b=2;
m=2;
h=(ba)/(4*m);
fork=1:4*m
x(k)=a+k*h;
325

end
tp=0;
j=1;
fork=1:m
tp=tp+(7*feval(f,a)+32*feval(f,x(j))+...
12*feval(f,x(j+1))+32*feval(f,x(j+2))+7*feval(f,x(j+3)));
a=x(4*k);
j=4*k+1;
end
tp=tp*h*2/45;

tnhtchphncamthmtadngchngtrnhctintbool.m:

clearall,clc
formatlong
f=inline(x.*sin(x));
a=0;
b=2;
m=2;
J=intbool(f,a,b,m)

8.CNGTHCTCHPHNFILON

Giscntnhtchphn:
b

J = f(x)cos(x)dx
a

LctacthdngcngthctchphnFilon:
xn

f(x)cos(tx)dx

x0

= h (th) [ f2n sin(tx 2n )f2n sin(tx 2n )] + (th)C 2n + (th)C 2n 1 +

2 4
th S2n
45

Trong:

a=x0,b=xn,t=
n

C 2n = f2i cos(tx 2i ) 0.5 f2n cos(tx 2n ) + f0cos(tx0 )


i =0

326

C 2n 1 = f2i1cos(tx 2i1 )
i =0
n

S2n 1 = f2i1 sin(tx 2i1 )


i =1

1 sin 2 sin 2

() = +
3

2 2

2
1 + cos sin 2
() = 2

2
3

sin cos
() = 4 3 2



Taxydnghmfilon()thchincccngthctrn:

functionint=filon(f,a,b,t,m,key)
%hamfilontinhgandungtichphan
b

% f (x)cos(tx)dx neukey=1,
a

%hay
b

% f (x)sin(tx)dx neukey=2,
a

%dungmdiemtheoquytacFilon(mle).
if(any(size(a)~=[11]))
error(Thongsoaphailaso.);
end
if(any(size(b)~=[11]))
error(Thongsobnhapvaophailaso.);
end
if(any(size(t)~=[11]))
error(Thongsotphailaso.);
end
if(any(size(m)~=[11]))
error(Thongsomphailaso.);
end
if(any([(fix(m)~=m)(rem(m,2)==0)]))
error(Thongsomphailasole.);
end
327

if(m<3)
error(Thongsomphailonhon3.);
end
if(all([(key~=1)(key~=2)]))
error(Thongsokeyphaila1hoac2.);
end
n=m1;
h=(ba)/n;
th=t*h;
thh=th*th;
if(abs(th)>=0.1)
s=sin(th);
c=cos(th);
alfa=(1.0+s*(c2.0*s/th)/th)/th;
beta=2.0*(1.0+c*c2.0*s*c/th)/thh;
gamma=4.0*(s/thc)/thh;
else
alfa=th*thh*(2.0/45.0+thh*(2.0/315.0+2.0*thh/4725.0));
beta=2.0/3.0+thh*(2.0/15.0+thh*(4.0/105.0+2.0*thh/567.0));
gamma=4.0/3.0+thh*(2.0/15.0+thh*(1.0/210.0thh/11340.0));
end
args=[ab];
fbounds=feval(f,args);
s1=sin(a*t);
s2=sin(b*t);
c1=cos(a*t);
c2=cos(b*t);
if(key==1)
sum=s2*fbounds(2)s1*fbounds(1);
sum0=0.5*(c1*fbounds(1)+c2*fbounds(2));
if(n>2)
args=(a+(2:2:n2)*h);
sum0=sum0+cos(t*args)*feval(f,args);
end
args=(a+(1:2:n1)*h);
sum1=cos(t*args)*feval(f,args);
328

else
sum=c1*fbounds(1)c2*fbounds(2);
%sum=(c1*fbounds(1)c2*fbounds(2));
sum0=0.5*(s1*fbounds(1)+s2*fbounds(2));
%if(n==2)
if(n>2)
args=(a+(2:2:n2)*h);
sum0=sum0+sin(t*args)*feval(f,args);
end
args=(a+(1:2:n1)*h);
sum1=sin(t*args)*feval(f,args);
end
int=h*(alfa*sum+beta*sum0+gamma*sum1);

Khitnhtchphntadngchngtrnhctintfilon.m:

clearall,clc
a=0;
b=2;
key=2;
t=3;
m=51;
f=inline((x.^3+1).*sin(x));
J=filon(f,a,b,t,key)

9.QUYTCHARDY
b

tnhtchphn J = f(x)dx tacthdngcngthcHardy:


a

x7

f(x)dx = 0.01h ( 28f

+ 162f2 + 220f4 + 162f6 + 28f7 )

x1

tngchnhxctadngphngphpchiaon[a,b]thnhmonv
trnmiontadngcngthcHardy.Taxydnghminthardy()thc
hincngthctrn:

functiontp=inthardy(f,a,b,m)
329

%TinhtichphanbangphuongphapHardy
h=(ba)/(6*m);
fork=1:6*m
x(k)=a+k*h;
end
tp=0;
j=1;
fork=1:m
tp=tp+(28*feval(f,a)+162*feval(f,x(j))+...
220*feval(f,x(j+2))+162*feval(f,x(j+4))+28*feval(f,x(j+5)));
a=x(6*k);
j=6*k+1;
end
tp=tp*h*0.01;

tnhtchphntadngchngtrnhctinthardy.m:

clearall,clc
formatlong
f=inline(exp(x).*sin(x),x);
a=0;
b=2;
m=20;
J=inthardy(f,a,b,m)

10.QUYTCDURANT
b

tnhtchphn J = f(x)dx tacthdngcngthcDurant:


a

xn

2 + 11 f + f + L + f + 11 f + 2 f
1
2
3
n2
n 1
n
10
10
5

f(x)dx = h 5 f

x1

Taxydnghmintdurant()thchincngthctrn:

functiontp=intdurant(f,a,b,n)
%TinhtichphanbangphuongphapDurant
h=(ba)/(n);
330

fork=1:n
x(k)=a+k*h;
end
tp=0;
fori=2:n2
tp=tp+feval(f,x(i));
end
tp=tp+0.4*feval(f,a)+1.1*feval(f,x(1))+...
1.1*feval(f,x(n1))+0.4*feval(f,x(n));
tp=h*tp;

tnhtchphntadngchngtrnhctintdurant.m:

clearall,clc
formatlong
f=inline(1./(1+x.^2));
a=0;
b=2;
n=50;
J=intdurant(f,a,b,n)

11.QUYTCSHOVELTON
b

tnhtchphn J = f(x)dx tacthdngcngthcShovelton:


a

x11

f(x)dx =

x1

5
h 8 ( f1 + f11 ) + 35 ( f2 + f4 + f8 + f10 ) + 15 ( f3 + f5 + f7 + f9 ) + 36f6
126

tngchnhxctadngphngphpchiaon[a,b]thnhmonv
trnmiontadngcngthcShovelton.Taxydnghm intshovelton()
thchincngthctrn:

functiontp=intshovelton(f,a,b,m)
%TinhtichphanbangphuongphapShovelton
h=(ba)/(10*m);
fork=1:10*m
x(k)=a+k*h;
331

end
tp=0;
j=1;
fork=1:m
tp=tp+8*(feval(f,a)+feval(f,x(j+9)))+...
35*(feval(f,x(j))+feval(f,x(j+2))+feval(f,x(j+6))+feval(f,x(j+8)))+...
15*(feval(f,x(j+1))+feval(f,x(j+3))+feval(f,x(j+5))+feval(f,x(j+7)))+...
36*feval(f,x(j+4));
a=x(10*k);
j=10*k+1;
end
tp=tp*h*5/126;

tnhtchphntadngchngtrnhctshovelton.m:

clearall,clc
formatlong
f=inline(1./(1+x.^2));
a=0;
b=2;
m=20;
J=intshovelton(f,a,b,m)

12.QUYTCWEDDLE
b

tnhtchphn J = f(x)dx tacthdngcngthcWeddle:


a

x7

f(x)dx = 0.3h ( f

+ 5f2 + f3 + 6f4 + f5 + 5f6 + f7 )

x1

tngchnhxctadngphngphpchiaon[a,b]thnhmonv
trn mi on ta dng cng thc Weddle. Ta xy dng hm intweddle()
thchincngthctrn:

functiontp=intweddle(f,a,b,m)
%TinhtichphanbangphuongphapWeddle
h=(ba)/(6*m);
332

fork=1:6*m
x(k)=a+k*h;
end
tp=0;
j=1;
fork=1:m
tp=tp+feval(f,a)+5*feval(f,x(j))+...
feval(f,x(j+1))+6*feval(f,x(j+2))+...
feval(f,x(j+3))+5*feval(f,x(j+4))+feval(f,x(j+5));
a=x(6*k);
j=6*k+1;
end
tp=tp*h*0.3;

tnhtchphntadngchngtrnhctweddle.m:

formatlong
f=inline(exp(x).*sin(x),x);
a=0;
b=2;
m=20;
J=intweddle(f,a,b,m)

13.CUPHNGGAUSS
1. Cc cng thc tch phn Gauss: Trong phn ny chng ta s xt mt s
phngphpcuphngGauss:
TchphnGaussLegendredngxpx:
b

f(t)dt
a

TchphnGaussHermitedngxpx:

t
e f(t)dt
2

TchphnGaussLaguerredngxpx:

f(t)dt

333

TchphnGaussChebyshev1dngxpx:
1

1
1 t2

f(t)dt

TchphnGaussChebyshev2dngxpx:
1

1 t 2 f(t)dt

2.TchphnGaussLegendre:Nuhmdidutchphnf(t)lathc
bcnhhnhaybng3(bng2n1)thtchphn:
b

f(t)dt

(1)

cthtnhchnhxcbi2(n)imbngcchdngcngthc:

J[t1,t2]=w1f(t1)+w2f(t2)
viw1vw2lcctrngsvt1,t2lccnt.

(2)

+1

w1f(t1 ) + w 2 f(t 2 ) = w1 + w 1dt = 2

f(t)=1

(3a)

w1f(t1 ) + w 2 f(t 2 ) = w1t1 + w 2 t 2 tdt = 0

(3b)

2
w1f(t1 ) + w 2f(t 2 ) = w1t 12 + w 2 t 22 t 2dt =
3
1

(3c)

(3d)

(4)

+1

f(t)=t

1
+1

f(t)=t2

+1

w1f(t1 ) + w 2 f(t 2 ) = w t + w t t 3dt = 0


3
1 1

f(t)=t

3
2 2

2
1

Nhn(3b)vi t vtrktqucho(3d)tac:

w 2 (t 32 t 12 t 2 ) = 0 nn t2=t1
Thayt2=t1vo(3b)tac:

(w1w2)t1=0 nn w1=w2
Thayw1=w2vo(3a)tac:
nn w1=w2=1

w1+w2=2
Thayw1=w2=1vo(3c)tac:
2
1
t12 + ( t 1 )2 = nn t1 = t 2 =

3
3
Nhvy(2)trthnh:
1 1
J [ t1 ,t 2 ] = f

+ f

3 3

334

nghalcngthcxpxnychotaktquchnhxcca(1)khin3.
Khi a thc di du tch phn c bc nh hn (2n 1) th cng thc
tchphnGaussLegendre:
n

J GL [ t1 ,t 2 ,K ,t n ] = w i f(t i )

(5)

i =1

chotchphnchnhxccaathc.Ccimnt(nnt)lnghimcaa
thcLegendrebcn:
n/2
(2n 2i)!
L n (t) = ( 1)i n
t n 2i

(6a)
2
i!(n
i)!(n
2i)!

i =0
haytnhtheocngthclp:
(2n 1)tL n 1 (t) (n 1)L n2 (t)
L n (t) =

(6b)

n
toraathcLegendretadnghmlegendre():

functionp=legendre(n)
%taoradathucLegendre
p0=1;
p1=[10];
ifn<=0
p=p0;
elseifn==1
p=p1;
end
fork=2:n
p=((2*k1)*[p10](k1)*[00p0])/k;
p0=p1;
p1=p;
end

Chonimnt,tacthtnhcctrngstngngcacngthctchphn
GaussLegendrenimbngcchgiihphngtrnhtuyntnh:

335

1
2
1
1 L 1 w n,1

t2
t i L t n w n,1
t1

t 22
t i2 L t 2n w n,i = 1(1)i / n

t1

M
M
M
M
M M
M

n 1 n 1 n 1

t2
ti
L t nn 1 w n,n 1(1)n / n
t1


trongphntthicavphiRHS(i)l:
+1
+1
1 i
1 ( 1)i
i 1

RHS(i) = t dt = t =

n
i

1
1

(8)

(7)

Thtctmnimntvcctrngswn,icacngthctchphnGauss
Legendrecvittronghmgausslegendre():

function[t,w]=gausslegendre(n)
ifn<0
fprintf(\nBaccuadathucLegendrephailasoduong\n);
return;
else
t=roots(legendre(n));%taothanhmothangcuamatran;
A(1,:)=ones(1,n);
b(1)=2;
fori=2:n%Pt.(7)
A(i,:)=A(i1,:).*t;
ifmod(n,2)==0
b(i)=0;
elseb(i)=2/n;%Pt.(8)
end
end
w=b/A;
end

Khi tnh tch phn trn on [a, b] ta phi bin i n v on [1, 1]


bngccht:
(b a)t + a + b
ba
x=

dx =
dt

(9)

2
2

336

Nh vy ta c th vit li cng thc tch phn Gauss Legendre trn


on[a,b]l:
b
+1
ba
f[x(t)]dt
J = f(x)dx =

2
a
1
vxpxbngcngthc:
ba n
(b a)t i + a + b

(10)
J [ x1 ,x 2 ,K ,x n ] =
w i f(xi ) vi xi =

2 i =1
2
Vicchuyninycthchinbnghmintglegendre():
functionJ=intglegendre(f,a,b,n)
[t,w]=gausslegendre(n);
x=((ba)*t+a+b)/2;%Pt.(9)
fx=feval(f,x);
J=w*fx*(ba)/2;%Pt.(10)

tnhtchphntadngchngtrnhctgausslegendre.m:

clc,clearall
%tinhtichphanhamf(x)trendoan[a,b]
%n<=25;
f=inline(exp(x).*sin(x),x);
a=0;
b=1;
n=20;
J=intglegendre(f,a,b,n)

3.TchphnGaussHermite:CngthctchphnGaussHermitecdng:
n

J GH [ t 1 ,t 2 ,K ,t n ] = w i f(t i )

(11)

i =1

dngtnhtchphncahmm e t nhnvif(t)lathcbcnhhn
(2n1)trnon[,]:
2

J=

t2

f(t)dt

(12)

(13a)

CcimntlnghimcaathcHermite:
n/2
( 1)i

Hn =
n(n 1)L(n 2i + 1)(2t)n 2i
i!
i =0

337

hay:
H n (t) = 2tH n 1 (t) Hn 1 (t)

(13b)

toracchscaathcHermitetheo(13b)taxydnghmhermite():

functionp=hermite(n)
%Hn+1(x)=2xHn(x)Hn(x)
ifn<=0
p=1;
else
p=[20];
forn=2:n
p=2*[p0][00polyder(p)];%Pt.(13b)
end
end

ChonimnttatmcctrngscacngthctchphnGaussHermite
bngcchgiihphngtrnh(7)vivphil:
+

RHS(1) =

t2

dt =

+ +

x2

(x 2 + y 2 )

dxdy =

r2

2rdr = e r

(14a)

RHS(n) = 0 nunchn
+

RHS(n) =

dx e y dy
+

e t

t 2 n 1

dt =

t
(2t)e

1 n2
t dt
2

(14b)

1
1
1
= e t t n 2 + (n 2) e t t n 3dt = (n 2)RHS(n 2)
2
2
2

Th tc tm n nt v cc trng s tng ng ca cng thc tch phn


GaussHermitecthchintronghmgausshermite():

function[t,w]=gausshermite(n)
ifn<0
error(BaccuadathucHermitephailasoduong);
end
t=roots(hermite(n));
2

338

A(1,:)=ones(1,n);
b(1)=sqrt(pi);
forn=2:n
A(n,:)=A(n1,:).*t;%Pt.(7)
ifmod(n,2)==1
b(n)=(n2)/2*b(n2);%Pt.(14)
else
b(n)=0;
end
end
w=b/A;

Taxydnghmintghermite()tnhtchphn:

functionJ=intglegendre(f,n)
[t,w]=gausshermite(n);
fx=feval(f,t);
J=w*fx;%Pt.(11)

tnhtchphntadngchngtrnhctgausshermite.m:

clc,clearall
f=inline((x^3+1)*sin(x),x);
n=15;
J=intghermite(@f1,n)

4. Tch phn Gauss Laguerre: Khi dng cng thc tch phn Gauss
Laguerre(5)trthnh:
n

J GLa [ t 1 ,t 2 ,K ,t n ] = w i f(t i )

(16)

(17)

i =1

vchotaktqucatchphn:
+

J= e t f(t)dt

CcimntlnghimcaathcLaguerrebcn:

339

Ln =
0

( 1)i
ni
ti
i! (n i)!i!

(18a)

hay:

(n + 1)L n +1 (t) = (2n + 1 t)L n (t) nL n 1 (t)

(18b)
toraathcLaguerrebcntadnghmlaguerre():

functionp=laguerre(n)
%Ln+1(x)=(2n+1x)Ln(x)nLn1(x)
p0=1;
p1=[11];
ifn<=0
p=p0;
elseifn==1
p=p1;
end
fork=2:n
p=([p10]+(2*k1)*[0p1](k1)*[00p0])/k;
p0=p1;
p1=p;
end

Chonnttitacthtmcctrngstngngbngcchgiihphng
trnhistuyntnh(7)vivphil:

RHS(1) = e tdt = e t 0 = 1
RHS(n) = e t

t n 1

t n 1

dt = e t

(19a)

(19b)

+ (n 1) e t t n 2dt
0

= (n 1)RHS(n 1)
tnhtoccntvtrngstngngtadnghmgausslaguerre():

function[t,w]=gausslaguerre(n)
ifn<0
error(BaccuadathucLaguerrephailasoduong);
end
t=roots(laguerre(n));
340

A(1,:)=ones(1,n);
b(1)=1;
fori=2:n
A(i,:)=A(i1,:).*t;%Pt.(7)
b(i)=(i1)*b(i1);%Pt.(15)
end
w=b/A;
Hmintglaguerre()dngtnhtchphn:

functionJ=intglaguerre(f,n)
[t,w]=gausslaguerre(n);
fx=feval(f,t);
J=w*fx;%Pt.(10)
tnhtchphntadngchngtrnhctgausslaguerre.m:

clearall,clc
formatlong
f=inline((x.^2).*cos(x),x);
n=10;
J=intglaguerre(f,n)

5. Tch phn Gauss Chebyshev: Cng thc tnh tch phn Gauss
Chebyshev1cdng:
n

J GC1 [ t 1 ,t 2 ,K ,t n ] = w i f(t i )

(20)

(21)

(22)

(23)

i =1

Cngthc(20)chotatnhtchphn:
+1

J =

1
1 t2

f(t)dt

CcimntlnghimcaathcChebyshevbcn:
(2i 1)
i=1,2,...,n

t i = cos
2n
Cctrngstngngl:

w in = i=1,2,...,n

341

Taxydnghm gausscheb1()tnhcctoccntvtrngstng
ng:

function[t,w]=gausscheb1(n)
ifn<0
error(BaccuadathucChebyshevphailasoduong);
end
fori=1:n
t(i)=cos((2*i1)*pi/(2*n));
w(i)=pi/n;
end

Hmintgcheb1()dngtnhtchphntheocngthcGaussChebyshev1:

functionJ=intgcheb1(f,n)
[t,w]=gausscheb1(n);
fx=feval(f,t);
fx=sqrt(1t.^2).*fx;
J=w*fx;%Pt.(21)
tnhmttchphnnotadngchngtrnhctgausscheb1.m:

clearall,clc
formatlong
f=inline(1./(1+x.^2));
n=16;
J=intgcheb1(f,n)

CngthctnhtchphnGaussChebyshev2cdng:
n

J GC1 [ t 1 ,t 2 ,K ,t n ] = w i f(t i )

(24)

(25)

(26a)

i =1

Cngthc(24)chotatnhtchphn:

J =

+1

1 t 2 f(t)dt

CcimntlnghimcaathcChebyshevbcn:
i
t i = cos

i=1,2,...,n
n +1

342

Cctrngstngngl:

i
w in =
sin 2

(26b)

i=1,2,...,n
n+1
n + 1
Taxydnghm gausscheb2()tnhcctoccntvtrngstng
ng:

function[t,w]=gausscheb2(n)
ifn<0
error(BaccuadathucChebyshevphailasoduong);
end
fori=1:n
t(i)=cos(i*pi/(n+1));
w(i)=(pi/(n+1))*(sin(i*pi/(n+1))).^2;
end

Hmintgcheb2()dngtnhtchphntheocngthcGaussChebyshev2:

functionJ=intgcheb2(f,n)
[t,w]=gausscheb2(n);
fx=feval(f,t);
fx=(1./sqrt(1t.^2)).*fx;
J=w*fx;%)

tnhmttchphnnotadngchngtrnhctgausscheb2.m:

clearall,clc
formatlong
f=inline(1./(1+x.^2));
n=16;
J=intgcheb2(f,n)

6.TchphnGaussviimkdlogarit:Taccngthccuphng:

i =1

f(x)ln(x)dx = A f(x )
i

Trongvin=6tac:

343

xi 0.0216334 0.129583
Ai 0.238764 0.308287

0.314020
0.245317

0.538657 0.756916 0.922669


0.142009 0.0554546 0.010169

Taxydnghmintlogarit()thchintchphnny:

functiontp=intlogarit(f)
n=6;
x=[0.0216344;0.129583;0.314020;0.538657;0.756916;0.922669];
A=[0.238764;0.308287;0.245317;0.142009;0.0554546;0.010169];
tp=0;
fori=1:n
t=feval(f,x(i));
tp=tp+A(i)*t;
end
tp=tp;
tnhtchphntadngchngtrnhctintlogarit.m:

clearall,clc
formatlong
f=inline((x.^3+1).*sin(x),x);
J=intlogarit(f)

14.TCHPHNGAUSSLOBATTO

Trong tch phn ny cc im cn trn v di u l nt ca cu


phng.CngthccuphngGaussLobattocdng:

n 1

i=2

f(x)dx = w1f(1) + w 2f(1) + wif(xi )

Ngoi hai im nt x = 1 v x = 1, cc im nt khc c trng s c xc


nhbng:
2
wi =

2
n(n 1) [ P (x )]
n 1

Taxydnghmgausslobatto()tnhccntvcctrngstngng:

function[x,w]=gausslobatto(N)
344

%TinhcacnutvatrongsoLegendreGaussLobatto
N1=N+1;
%DautiendungcacnutChebyshevGaussLobatto
x=cos(pi*(0:N)/N);
%TinhmatranLegendreVandermonde
P=zeros(N1,N1);
xold=2;
whilemax(abs(xxold))>eps
xold=x;
P(:,1)=1;
P(:,2)=x;
fork=2:N
P(:,k+1)=((2*k1)*x.*P(:,k)(k1)*P(:,k1))/k;
end
x=xold(x.*P(:,N1)P(:,N))./(N1*P(:,N1));
end
w=2./(N*N1*P(:,N1).^2);

Thngthng,ta cntnhtchphntrnon[a,b]nncnibin.Tch
phntrn[a,b]cahmf(x)ctnhnhhmintgausslobatto():

functionJ=intgausslobatto(f,n,a,b)
[t,w]=gausslobatto(n);
x=((ba)*t+a+b)/2;%Pt.(9)
fx=feval(f,x);
J=w*fx*(ba)/2;%Pt.(10)

tnh tch phn ca hm ta dng chng trnh chng trnh


ctintgausslobatto.m:

clearall,clc
%tinhtichphanhamf(x)trendoan[a,b]
%n<=25;
f=inline((x.^3+1).*sin(x),x);
a=0;
b=1;
345

n=6;
J=intgausslobatto(f,n,a,b)

15.TCHPHNGAUSSKRONROD
Taxttchphn:
b

J = f(x)dx
a

TheocngthccuphngGausKrnodtac:

i =1

J = f(x)dx = w i f(x i )

Trongccntlxivcctrngstngnglwi.Ccgitrnaykhin=
41clutronghmkronrod:

function[x,w]=kronrod
%cacnutvatrongsotuongungtrongtichphanGaussKronrod
x(1)=0.9988590315882777;
x(2)=0.9931285991850949;
x(3)=0.9815078774502503;
x(4)=0.9639719272779138;
x(5)=0.9408226338317548;
x(6)=0.9122344282513259;
x(7)=0.8782768112522820;
x(8)=0.8391169718222188;
x(9)=0.7950414288375512;
x(10)=0.7463319064601508;
x(11)=0.6932376563347514;
x(12)=0.6360536807265150;
x(13)=0.5751404468197103;
x(14)=0.5108670019508271;
x(15)=0.4435931752387251;
x(16)=0.3737060887154196;
x(17)=0.3016278681149130;
x(18)=0.2277858511416451;
x(19)=0.1526054652409227;
x(20)=0.7652652113349733E01;
346

x(21)=0.0;
x(22)=0.7652652113349733E01;
x(23)=0.1526054652409227;
x(24)=0.2277858511416451;
x(25)=0.3016278681149130;
x(26)=0.3737060887154196;
x(27)=0.4435931752387251;
x(28)=0.5108670019508271;
x(29)=0.5751404468197103;
x(30)=0.6360536807265150;
x(31)=0.6932376563347514;
x(32)=0.7463319064601508;
x(33)=0.7950414288375512;
x(34)=0.8391169718222188;
x(35)=0.8782768112522820;
x(36)=0.9122344282513259;
x(37)=0.9408226338317548;
x(38)=0.9639719272779138;
x(39)=0.9815078774502503;
x(40)=0.9931285991850949;
x(41)=0.9988590315882777;

w(1)=0.3073583718520532E02;
w(2)=0.8600269855642942E02;
w(3)=0.1462616925697125E01;
w(4)=0.2038837346126652E01;
w(5)=0.2588213360495116E01;
w(6)=0.3128730677703280E01;
w(7)=0.3660016975820080E01;
w(8)=0.4166887332797369E01;
w(9)=0.4643482186749767E01;
w(10)=0.5094457392372869E01;
w(11)=0.5519510534828599E01;
w(12)=0.5911140088063957E01;
w(13)=0.6265323755478117E01;
w(14)=0.6583459713361842E01;
347

w(15)=0.6864867292852162E01;
w(16)=0.7105442355344407E01;
w(17)=0.7303069033278667E01;
w(18)=0.7458287540049919E01;
w(19)=0.7570449768455667E01;
w(20)=0.7637786767208074E01;
w(21)=0.7660071191799966E01;
w(22)=0.7637786767208074E01;
w(23)=0.7570449768455667E01;
w(24)=0.7458287540049919E01;
w(25)=0.7303069033278667E01;
w(26)=0.7105442355344407E01;
w(27)=0.6864867292852162E01;
w(28)=0.6583459713361842E01;
w(29)=0.6265323755478117E01;
w(30)=0.5911140088063957E01;
w(31)=0.5519510534828599E01;
w(32)=0.5094457392372869E01;
w(33)=0.4643482186749767E01;
w(34)=0.4166887332797369E01;
w(35)=0.3660016975820080E01;
w(36)=0.3128730677703280E01;
w(37)=0.2588213360495116E01;
w(38)=0.2038837346126652E01;
w(39)=0.1462616925697125E01;
w(40)=0.8600269855642942E02;
w(41)=0.3073583718520532E02;

Tadnghmintgkronrod()chuynonlytchphnt[11]sangon
[a,b]:

functionJ=intgkronrod(f,a,b)
[t,w]=kronrod;
x=((ba)*t+a+b)/2;)
fx=feval(f,x);
J=w*fx*(ba)/2;
348

tnhtchphntadngchngtrnhctgausskronrod.m:

clc,clearall
%tinhtichphanhamf(x)trendoan[a,b]
f=@f2;
a=0;
b=1;
J=intgkronrod(f,a,b)

16.TCHPHNGAUSSJACOBI

TchphnGaussJacobi,cngiltchphnMehler,dngtnhtch
phndng:

Taxttchphn:
b

J = (1 x) (1 + x) f(x)dx
a

TheocngthccuphngGausJacobitac:

i =1

J = f(x)dx = w i f(x i )

TrongxilnnghimcaathcJacobi.CccngthctnhathcJacobi
l:
P0( , ) (x) = 1

P1( , ) (x) = 0.5 [ 2( + 1) + ( + + 2)(x 1)]

(b 2n + b 3n x)Pn( 1, ) (x) b 4n Pn( 2, ) (x)


P (x) =

b1n
Vi: b1n=2i(i++)(2i++2)

b2n=(2i++1)(22)

b3n=(2i++2)(2i++1)(2i++)

b4n=2(i+1)(i+1)(2i++)
Cctrngswicxcnhbng:
(i + + 1)(i + + 1)
2 2i+++1 n!
wi =

2
(i + + + 1)
(1 xi2 ) [ Vn (xi )]
( , )
n

vi:
2 n n!
Vn = P (x)

( 1)n
Taxydnghmgaussjacobi()tmxivwi:
( , )
n

349

function[x,w]=gaussjacobi(n,alfa,beta)
%tinhcactrongsovahoanhdotrongtichphanGaussJacobi
p=[0.5*(alfa+beta+2)0.5*(alfabeta)];
a=1;
b=p;
fori=2:n+1
b1=2*i*(i+alfa+beta)*(2*i+alfa+beta2);
b2=(2*i+alfa+beta1)*(alfa^2beta^2)/b1;
b3=((2*i+alfa+beta2)*(2*i+alfa+beta1)*(2*i+alfa+beta))/b1;
b4=(2*(i+alfa1)*(i+beta1)*(2*i+alfa+beta))/b1;
s=[b3b2];
ifi==n+1
pn1=conv(s,b)[00b4*a];
break;
else
p=conv(s,b)[00b4*a];
end
a=b;
b=p;
end
x=roots(p);
w=zeros(n,1);
dv=polyder(p);
ifmod(n,2)==1
sign=1;
else
sign=1;
end
dv=dv*(2^n)*factorial(n)/sign;
pn1=pn1*(2^(n+1))*factorial(n+1)/sign;
fori=1:n
num=(2*n+alfa+beta+...
2)*gamma(n+alfa+1)*gamma(n+beta+1)*(2^(2*n+alfa+beta+1))*factorial(n);
den=(n+alfa+beta+1)*gamma(n+alfa+beta+1)*polyval(dv,...
x(i))*polyval(pn1,x(i));
w(i)=num/den;
350

end

Tiptheotaxydnghmintgaussjacobi()tnhtchphn:
functionJ=intgaussjacobi(f,n,alf,bta)
[t,w]=gaussjacobi(n,alf,bta);
fx=feval(f,t);
J=w*fx;

tnhtchphntadngchngtrnhctgaussjacobi.m:

clearal,clc
f=inline(exp(x).*sin(x),x);
n=6;%n<=40
alfa=1;
beta=0;
J=intgaussjacobi(f,n,alfa,beta)

17.TCHPHNRADAU

CuphngRadaudngtnhtchphn:
1

J = f(x)dx

(1)

(2)

TheocngthccuphngRadautac:

i=2

J = f(x)dx = w1f( 1) + w i f(xi )

im(1)lmtmtnttrongsccntcacuphng.Cchonhcn
lilnghimcaathc:
Pn 1 (x) Pn (x)

(3)

1+ x
TrongP(x)lathcLegendre.Cctrngstngngctnhtheo:
1 xi

wi = 2

(4)
2
n [ Pn 1 (xi )]

vimcuic:
2
w1 = 2

n
Taxydnghmradau()tnhcchonhxivtrngswi:

351

function[x,w]=radau(n)
%TinhcachoanhdovatrongsotrongcauphuongRadau
tol=1e8;
%danhgiabandaucachoanhdolacanutChebyshevGaussRadau
x(1:n,1)=cos(2.0*pi*(0:n1)/(2*n1));
p=zeros(n,n+1);
xold(1:n,1)=2.0;
while(tol<max(abs(x(1:n,1)xold(1:n,1))))
xold=x;
p(1,1:n+1)=(1.0).^(0:n);
p(2:n,1)=1.0;
p(2:n,2)=x(2:n,1);
forj=2:n
p(2:n,j+1)=((2*j1)*x(2:n,1).*p(2:n,j)+(j+1)*p(2:n,j1))/j;
end
x(2:n,1)=xold(2:n,1)((1.0xold(2:n,1))/n)...
.*(p(2:n,n)+p(2:n,n+1))./(p(2:n,n)p(2:n,n+1));
end
w=zeros(n,1);
w(1)=2/n^2;

Tip theo ta xy dng hm intradau(), tnh tch phn. Trong hm ta i


cnlytchphntrongkhong[1,1]thnhtchphntrongkhong:

functionJ=intradau(f,n,a,b)
[t,w]=radau(n);
x=((ba)*t+a+b)/2;
fx=feval(f,x);
J=w*fx*(ba)/2;

tnhtchphntadngchngtrnhctradau.m:

clearal,clc
f=inline(x.*sin(x));
n=6;%n<=40
a=1;
352

b=3;
J=intradau(f,n,a,b)

18.TCHPHNCHEBYSHEVRADAU
CuphngChebyshevRadaudngtnhtchphn:
1

J = f(x)dx

(1)

(2)

TheocngthccuphngChebyshevRadautac:

i=2

J = f(x)dx = w i [ f(xi ) f( xi )]

Cchonhxivtrngstngngwichotrongbng:

0.3549416
0.6433097
0.7783202
xi
wi
0.1223363
0.1223363
0.1223363

Taxydnghmchebradau()chaccgitrxvw:

function[x,w]=chebradau
x(1)=0.3549416;
x(2)=0.6433097;
x(3)=0.7783202;
x(4)=0.9481574;

w(1)=0.1223363;
w(2)=0.1223363;
w(3)=0.1223363;
w(4)=0.1223363;

vhmintchebradau()tnhtchphn:

functionJ=intchebradau(f,a,b)
[t,w]=chebradau;
fx1=feval(f,t);
fx2=feval(f,t);
J=(w*fx1w*fx2);

0.9481574
0.1223363

353

tnhtchphncamthmcthtadngchngtrnhctchebradau.m:

clearal,clc
f=inline(exp(x).*sin(x),x);
J=intchebradau(f)

19.TCHPHNGAUSSRADAU

CngthccuphngGaussRadaucdng:

n 1

i=2

f(x)dx = w1f(1) + w 2f(1) + wif(xi )

Ngoi hai im nt x = 1, cc im nt khc l nghim ca a thc Pn(x) +


Pn+1(x),viP(x)lathcLegendre.Cctrngscxcnhbng:
2

w1 =

(n + 1)2
1 xi

wi =
2
(n + 1) [ Pn +1 (xi )]
Ta xy dng hm gaussradau() tnh cc honh v trng s ca cu
phng:

function[x,w]=gaussradau(N)
%tinhcacnutvatrongsocuacauphuongGaussRadau
N1=N+1;
%dungcacnutChebyshevGaussRadaulamxapxidautien
x=cos(2*pi*(0:N)/(2*N+1));
P=zeros(N1,N1+1);
xold=2;
free=2:N1;
whilemax(abs(xxold))>eps
xold=x;
P(1,:)=(1).^(0:N1);
P(free,1)=1;
P(free,2)=x(free);
fork=2:N1
P(free,k+1)=((2*k1)*x(free).*P(free,k)(k1)*P(free,k1))/k;
end
354

x(free) = xold(free) ((1xold(free))/N1).*(P(free,


N1+1))..../(P(free,N1)P(free,N1+1));
endP=P(1:N1,1:N1);
w=zeros(N1,1);
w(1)=2/N1^2;
w(free)=(1x(free))./(N1*P(free,N1)).^2;

N1)

P(free,

Tadnghmintgaussradau()tnhtchphncahmf(x)trnon[a,b]:

functionJ=intgaussradau(f,n,a,b)
[t,w]=gaussradau(n);
x=((ba)*t+a+b)/2;
fx=feval(f,x);
J=w*fx*(ba)/2;

tnhtchphncahmtadngchngtrnhctgaussradau.m:

clearall,clc
f=inline(exp(x).*sin(x),x);
n=6;
a=1;
b=3;
J=intgaussradau(f,n,a,b)

20.ATHCNISUYVTCHPHNS

Khi hm c cho di dng bng s, tnh tnh phn ca hm ta


thchinccbcsau:

Tmathcnisuy,cthlathcLagrange,athcNewton...

Tmtchphncaathcnisuy
Sauychngtasxydngchngtrnhctinterp.mtnhtchphndng
athcnisuyLagrange:

clearall,clc
x=[1.00001.20001.40001.60001.80002.0000];
y=[1.92211.97561.65170.85010.49842.4199];
l=lagrange(x,y);
355

n=length(l);
p=conv(l,[10]);
n=length(p);
fori=1:n1
q(i)=p(i)/(ni);
end
q(n)=p(n);
tp=polyval(q,x(length(x)))polyval(q,x(1));

21.TCHPHNKP
1. Khi nim chung: Ta kho st tch phn ca hm z = f(x, y) trn min
R = {(x,y|a x b,c(x) y d(x)} nhhnhv.Tacntnhtchphn:
b

J = f(x, y)dxdy =
R

d(x)

f(x,y)dy

dx
c(x)

d(x)

hx0,y2
hx1,y2

hx0,y1 hx1,y1

a
x0 hx1 x1 hx2 x2

Cngthcgnngcatchphnl:

i =1

j=1

c(x)
b
hxm xm

J [a,b,c(x),d(x)] = w i v jf(x i ,y i ,j )

vicctrngswi,vjtuthucvochtnhtchphnhmmtbin.
Taxydnghm int2simpson()tnhtchphnkpbngcngthc
Simpson.

functionJ=int2simpson(f,a,b,c,d,m,n)
% tich phan kep cua ham f(x,yen mien R = {(x,y)|a <= x <= b, c(x) <= y <=
d(x)}
356

%dungquytacSimpson
ifceil(m)~=floor(m)%berongcodinhcuacacdoantrenx
hx=m;
m=ceil((ba)/hx);
end
ifmod(m,2)~=0
m=m+1;
end
hx=(ba)/m;
i=1:m+1;
x=a+(i1)*hx;
ifisnumeric(c)
cx(i)=c;%neuclahangso
else
cx(i)=feval(c,x(i));%khiclahamcuacx
end
ifisnumeric(d)
dx(i)=d;%neudlahangso
else
dx(i)=feval(d,x(i));%khidlahamcuax
end
ifceil(n)~=floor(n)%berongcodinhtheoy
hy=n;
nx(i)=ceil((dx(i)cx(i))/hy);
ind=find(mod(nx(i),2)~=0);
nx(ind)=nx(ind)+1;
else%sokhoangcodinh
ifmod(n,2)~=0
n=n+1;
end
nx(i)=n;
end
fori=1:m+1
sx(i)=simpsonfxy(f,x(i),cx(i),dx(i),nx(i));
end
kodd=2:2:m;
357

keven=3:2:m1;%thesetofodd/evenindices
J=hx/3*(sx(1)+sx(m+1)+4*sum(sx(kodd))+2*sum(sx(keven)));

functionJf=simpsonfxy(f,x,c,d,n)
%tichphanmotbiencuaf(x,y)voiRy={c<=y<=d}
ifnargin<5
n=100;
end
ifabs(dc)<eps|n<=0
Jf=0;
return;
end
ifmod(n,2)~=0
n=n+1;
end
h=(dc)/n;
y=c+[0:n]*h;
fxy=feval(f,x,y);
fxy(find(fxy==inf))=realmax;
fxy(find(fxy==inf))=realmax;
kodd=2:2:n;
keven=3:2:n1;
Jf=h/3*(fxy(1)+fxy(n+1)+4*sum(fxy(kodd))+2*sum(fxy(keven)));

tnhthtchcahnhcutadngchngtrnhctint2simp.m:
clearall,clc
%Tinhthetichhinhcau
x=[1:0.05:1];
y=[0:0.05:1];
[X,Y]=meshgrid(x,y);
f=inline(sqrt(max(1x.*xy.*y,0)),x,y);
Z=f(X,Y);
mesh(x,y,Z);
a=1;
b=1;
c=0;
358

d=inline(sqrt(max(1x.*x,0)),x);
Vs1=int2simpson(f,a,b,c,d,100,100)%sodiemchotruoc
error1=Vs1pi/3
Vs2=int2simpson(f,a,b,c,d,0.01,0.01)%berongcacdoanchotruoc
error2=Vs2pi/3

359

You might also like