際際滷

際際滷Share a Scribd company logo
116
Ch測ng 9 : C存c vn 速 v ma trn
則1.則nh th淡c c単a ma trn
Cho m辿t ma trn vu束ng cp n.Ta cn tm 速nh th淡c c単a n達.Tr鱈c ht ch坦ng ta nh他c
l孫i m辿t s竪 tnh cht quan tr辰ng c単a 速nh th淡c:
- nu nh息n tt c其 c存c phn t旦 c単a m辿t h袖ng (hay c辿t) v鱈i k th 速nh th淡c 速樽c nh息n
v鱈i k
- 速nh th淡c kh束ng 速脱i nu ta c辿ng th捉m v袖o m辿t h袖ng t脱 h樽p tuyn tnh c単a c存c
h袖ng cn l孫i.
Ta s 存p d担ng c存c tnh cht n袖y 速 tnh 速nh th淡c c単a m辿t ma trn cp 4 nh sau(ph測ng
ph存p n袖y c達 th m谷 r辿ng cho m辿t ma trn cp n) b損ng ph測ng ph存p tr担:












=
44434241
34333231
24232221
14131211
aaaa
aaaa
aaaa
aaaa
A
Ly gi存 tr tr担 l袖 p1= a11.Ta chia c存c phn t旦 c単a h袖ng th淡 nht cho p1= a11 th 速nh th淡c s l袖
D/p1 (theo tnh cht 1) v袖 ma trn cn l孫i l袖:











 霞霞
44434241
34333231
24232221
141312
aaaa
aaaa
aaaa
aaa1
Ly h袖ng 2 tr探 速i h袖ng 1 速揃 nh息n v鱈i a21,ly h袖ng 3 tr探 速i h袖ng 1 速揃 nh息n v鱈i a31 v袖 ly h袖ng
4 tr探 速i h袖ng 1 速揃 nh息n v鱈i a41 (thay h袖ng b損ng t脱 h樽p tuyn tnh c単a c存c h袖ng cn l孫i) th
速nh th淡c vn l袖 D/p1 v袖 ma trn l袖:












霞霞
霞霞
霞霞
霞霞
444342
343332
242322
141312
aaa0
aaa0
aaa0
aaa1
Ly gi存 tr tr担 l袖 222 ap = .Ta chia c存c phn t旦 c単a h袖ng th淡 hai cho p2 th 速nh th淡c s l袖
D/(p1p2) v袖 ma trn cn l孫i l袖:












霞霞
霞霞
霞霞霞
霞霞
444342
343332
2423
141312
aaa0
aaa0
aa10
aaa1
Ly h袖ng 1 tr探 速i h袖ng 2 速揃 nh息n v鱈i 12a ,ly h袖ng 3 tr探 速i h袖ng 2 速揃 nh息n v鱈i 32a v袖 ly h袖ng
4 tr探 速i h袖ng 2 速揃 nh息n v鱈i 42a th 速nh th淡c vn l袖 D/p1 v袖 ma trn l袖:
th 速nh th淡c vn l袖 D/(p1p2) v袖 ma trn l袖:
117












霞霞霞
霞霞霞
霞霞霞
霞霞霞
4443
3433
2423
1413
aa00
aa00
aa10
aa01
Tip t担c ly h袖ng 3 r奪i h袖ng 4 l袖m tr担 th ma trn s l袖:










1000
0100
0010
0001
則nh th淡c c単a ma trn n袖y l袖 D/(p1p2p3p4)= D/( 44332211 aaaa 霞霞霞霞霞 ) =1 n捉n 速nh th淡c c単a ma trn A
l袖 D = p1p2p3p4.
Sau 速息y l袖 ch測ng trnh tm 速nh th淡c c単a m辿t ma trn:
Ch測ng trnh 9-1
//tinh dinh thuc
#include <conio.h>#include <stdio.h>#include <ctype.h>
#include <stdlib.h>
void main()
{
int i,j,k,n,ok1,ok2,t;
float d,c,e,f,g,h;
float a[50][50];
char tl;
clrscr();
printf("** TINH DINH THUC CAP n **");
printf("n");
printf("n");
printf("Cho cap cua dinh thuc n = ");
scanf("%d",&n);
printf("Nhap ma tran an");
for (i=1;i<=n;i++)
{
printf("Dong %d:n",i);
for (j=1;j<=n;j++)
{
printf("a[%d][%d] = ",i,j);
scanf("%f",&a[i][j]);
}
printf("n");
}
printf("n");
printf("Ma tran a ma ban da nhapn");
printf("n");
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
118
printf("%.5ft",a[i][j]);
printf("n");
}
printf("n");
t=1;
flushall();
while (t)
{
printf("Co sua ma tran a khong(c/k)?");
scanf("%c",&tl);
if (toupper(tl)=='C')
{
printf("Cho chi so hang can sua : ");
scanf("%d",&i);
printf("Cho chi so cot can sua : ");
scanf("%d",&j);
printf("a[%d][%d] = ",i,j);
scanf("%f",&a[i,j]);
}
if (toupper(tl)=='K')
t=0;
}
printf("Ma tran a ban daun");
printf("n");
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
printf("%.5ft",a[i][j]);
printf("n");
}
printf("n");
d=1;
i=1;
ok2=1;
while ((ok2)&&(i<=n))
{
if (a[i][i]==0)
{
ok1=1;
k=k+1;
while ((ok1)&&(k<=n))
if (a[k,i]!=0)
{
for (j=i;j<=n;j++)
{
c=a[i][j];
a[i][j]=a[k][j];
a[k][j]=c;
}
d=-d;
119
ok1=0;
}
else
k=k+1;
if (k>n)
{
printf("n");
printf("** MA TRAN SUY BIEN **");
ok2=0;
d=0;
}
}
if (a[i][i]!=0)
{
c=a[i][i];
for (j=i+1;j<=n;j++)
a[i][j]=a[i][j]/c;
for (k=i+1;k<=n;k++)
{
c=a[k][i];
for (j=i+1;j<=n;j++)
a[k][j]=a[k][j]-a[i][j]*c;
}
}
i=i+1;
}
if (ok2)
{
for (i=1;i<=n;i++)
d=d*a[i][i];
printf("n");
printf("** GIA TRI DINH THUC D **");
printf("n");
printf("%.3f",d);
}
getch();
}
則2.Nghch 速其o ma trn
G辰i A-1
l袖 ma trn nghch 速其o c単a m辿t ma trn A bc n ta c達 AA-1
= E.(trong biu
th淡c n袖y E l袖 m辿t ma trn vu束ng c達 c存c phn t旦 tr捉n 速棚ng cho chnh b損ng 1). D孫ng c単a
ma trn E,v d担 cp 4,l袖:










=
1000
0100
0010
0001
E
120
Ph測ng ph存p lo孫i tr探 速 nhn 速樽c ma trn nghch 速其o A-1
速樽c th湛c hin qua nhiu
giai 速o孫n (n),m巽i m辿t giai 速o孫n g奪m hai b鱈c.則竪i v鱈i giai 速o孫n th淡 k:
- chun ho存 phn t旦 akk b損ng c存ch nh息n h袖ng v鱈i nghch 速其o c単a n達
- l袖m cho b損ng kh束ng c存c phn t旦 pha tr捉n v袖 pha d鱈i 速棚ng cho cho 速n c辿t th淡
k.Khi k = n th A(k)
s tr谷 th袖nh ma trn 速測n v v袖 E tr谷 th袖nh A-1
V d担: Tnh ma trn nghch 速其o c単a ma trn








=
211
121
112
A
Ta vit l孫i ma trn A v袖 ma trn 速測n v t測ng 淡ng v鱈i n達








=








=
100
010
001
E
211
121
112
A
Giai 速o孫n 1: B鱈c a: Nh息n h袖ng 1 v鱈i 1/a11,ngha l袖 a,
1j = a1j/a11 速竪i v鱈i dng th淡 nht,a,
ij =
aij 速竪i v鱈i c存c dng kh存c








=








=
100
010
0021
E
211
121
21211
A
B鱈c b: Tr探 h袖ng 3 v袖 h袖ng 2 cho h袖ng 1,ngha l袖 a(1)
1j = aij - ai1aij 速竪i v鱈i i 
1.









=








=
1021
0121
0021
E
23210
21230
21211
A
Giai 速o孫n 2: B鱈c a: Ly h袖ng 2 l袖m chun,nh息n h袖ng 2 v鱈i 2/3,速 nguy捉n c存c h袖ng kh存c









=








=
1021
03231
0021
E
23210
3110
21211
A
B鱈c b: Ly h袖ng 1 tr探 速i h袖ng 2 nh息n 1/2 v袖 ly h袖ng 3 tr探 速i h袖ng 2 nh息n
1/2











=








=
13131
03231
03132
E
3400
3110
3101
A
Giai 速o孫n 3: B鱈c a: Ly h袖ng 3 l袖m chun,nh息n h袖ng 3 v鱈i 3/4,速 nguy捉n c存c h袖ng kh存c











=








=
434141
03231
03132
E
100
3110
3101
A
B鱈c b: Ly h袖ng 1 tr探 速i h袖ng 3 nh息n 1/3 v袖 ly h袖ng 2 tr探 速i h袖ng 3 nh息n
1/3











=








=
434141
414341
414143
E
100
010
001
A
Nh vy A-1
l袖:
121











=

434141
414341
414143
A
1
存p d担ng ph測ng ph存p n袖y ch坦ng ta c達 ch測ng trnh sau:
Ch測ng trnh 9-2
#include <conio.h>#include <stdio.h>#include <math.h>#include <stdlib.h>#include
<ctype.h>void main() { int i,j,k,n,t,t1;float c,a[50][50],b[50][50]; char tl; clrscr();
printf(" **MA TRAN NGHICH DAO** n");
printf("Cho bac cua ma tran n = ");
scanf("%d",&n);
printf("Vao ma tran ban dau an");
for (i=1;i<=n;i++)
{
printf("Vao hang thu %d :n",i);
for (j=1;j<=n;j++)
{
printf("a[%d][%d] = ",i,j);
scanf("%f",&a[i][j]);
}
printf("n");
}
printf("n");
printf("Ma tran ban da nhapn");
printf("n");
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
printf("%.5ft",a[i][j]);
printf("n");
}
t=1;
flushall();
while (t)
{
printf("nCo sua ma tran khong(c/k)?");
scanf("%c",&tl);
if(toupper(tl)=='C')
{
printf("Cho chi so hang can sua : ");
scanf("%d",&i);
printf("Cho chi so cot can sua : ");
scanf("%d",&j);
printf("a[%d][%d] = ",i,j);
scanf("%f",&a[i][j]);
}
if (toupper(tl)=='K')
t=0;
}
printf("nMa tran ban daun");
122
printf("n");
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
printf("%.5ft",a[i][j]);
printf("n");
}
printf("n");
for (i=1;i<=n;i++)
for (j=n+1;j<=2*n;j++)
{
if (j==i+n)
a[i][j]=1;
else
a[i][j]=0;
}
i=1;
t1=1;
while (t1&&(i<=n))
{
if (a[i][i]==0)
{
t=1;
k=i+1;
while (t&&(k<=n))
if (a[k][i]!=0)
{
for (j=1;j<=2*n;j++)
{
c=a[i][j];
a[i][j]=a[k][j];
a[k][j]=c;
}
t=0;
}
else
k=k+1;
if (k==n+1)
{
if (a[i][k-1]==0)
{
printf("MA TRAN SUY BIENn ");
t1=0;
}
}
}
if (a[i][i]!=0)
{
c=a[i][i];
for (j=i;j<=2*n;j++)
123
a[i][j]=a[i][j]/c;
}
for (k=1;k<=n;k++)
{
if (k!=i)
{
c=a[k][i];
for (j=i;j<=2*n;j++)
a[k][j]=a[k][j]-a[i][j]*c;
}
}
i=i+1;
}
if (t1)
{
printf("n");
printf("nMA TRAN KET QUAn");
printf("n");
for (i=1;i<=n;i++)
{
for (j=n+1;j<=2*n;j++)
printf("%.4ftt",a[i][j]);
printf("n");
}
printf("n");
}
getch();
}
D誰ng ch測ng trnh tnh nghch 速其o c単a ma trn:








678
789
899
cho ta kt qu其











991
9102
121
則3.Tch hai ma trn
Gi其 s旦 ta c達 ma trn Amn v袖 ma trn Bnp.Tch c単a Amn v袖 Bnp l袖 ma trn Cmp trong 速達
m巽i phn t旦 c単a Cmp l袖: 
=
=
n
1k
kjikij bac
Ch測ng trnh d鱈i 速息y th湛c hin nh息n hai ma trn v鱈i nhau.
Ch測ng trnh 9-3
#include <conio.h>#include <stdio.h>#include <math.h>#include <stdlib.h>#include
<ctype.h>
#define max 50
void main()
124
{
int n,l,m,i,j,k,t;
float a[max][max],b[max][max],c[max][max];
char tl;
clrscr();
printf("Cho so hang cua ma tran a : ");
scanf("%d",&n);
printf("Cho so cot cua ma tran a : ");
scanf("%d",&l);
printf("Cho so cot cua ma tran b : ");
scanf("%d",&m);
printf("nNHAP MA TRAN An");
for (i=1;i<=n;i++)
for (j=1;j<=l;j++)
{
printf("a[%d][%d] = ",i,j);
scanf("%f",&a[i][j]);
}
printf("n");
printf("Ma tran a ma ban da nhapn");
for (i=1;i<=n;i++)
{
for (j=1;j<=l;j++)
printf("%10.5f",a[i][j]);
printf("n");
}
flushall();
t=1;
while (t)
{
printf("Co sua ma tran khong(c/k)?");
scanf("%c",&tl);
if (toupper(tl)=='C')
{
printf("Cho chi so hang can sua : ");
scanf("%d",&i);
printf("Cho chi so cot can sua : ");
scanf("%d",&j);
printf("a[%d][%d] = ",i,j);
scanf("%f",&a[i][j]);
}
if (toupper(tl)=='K')
t=0;
}
printf("Ma tran a ban dau");
printf("n");
for (i=1;i<=n;i++)
{
for (j=1;j<=l;j++)
125
printf("%10.5f",a[i][j]);
printf("n");
}
printf("n");
printf("NHAP MA TRAN Bn");
for (i=1;i<=l;i++)
for (j=1;j<=m;j++)
{
printf("b[%d][%d] = ",i,j);
scanf("%f",&b[i][j]);
}
printf("n");
printf("Ma tran b ban da nhapn");
for (i=1;i<=l;i++)
{
for (j=1;j<=m;j++)
printf("%10.5f",b[i][j]);
printf("n");
}
flushall();
t=1;
while (t)
{
printf("Co sua ma tran khong(c/k)?");
scanf("%c",&tl);
if (toupper(tl)=='C')
{
printf("Cho chi so hang can sua : ");
scanf("%d",&i);
printf("Cho chi so cot can sua : ");
scanf("%d",&j);
printf("b[%d][%d] = ",i,j);
scanf("%f",&b[i][j]);
}
if (toupper(tl)=='K')
t=0;
}
printf("Ma tran b ban dau");
printf("n");
for (i=1;i<=l;i++)
{
for (j=1;j<=m;j++)
printf("%10.5f",b[i][j]);
printf("n");
}
printf("n");
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
{
126
c[i][j]=0;
for (k=1;k<=l;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
printf("Ma tran tich c :n");
for (i=1;i<=n;i++)
{
for (j=1;j<=m;j++)
printf("%10.5f",c[i][j]);
printf("n");
}
getch();
}
D誰ng ch測ng trnh tnh tnh hai ma trn ta nhn 速樽c kt qu其














=


















1214
221
11148
105
343
221
35
01
31
12
則4.Gi存 tr ri捉ng v袖 vec t測 ri捉ng c単a ma trn
1.Kh存i nim chung: Trong nghi捉n l thuyt v袖 淡ng d担ng,ta gp b袖i to存n v ma trn cp
n.Cho m辿t ma trn A cp n,gi存 tr 了 速樽c g辰i l袖 gi存 tr ri捉ng v袖 vect測 X 速樽c g辰i l袖 vect測
ri捉ng c単a ma trn A nu:
AX = 了X (1)
Vect測 ri捉ng ph其i l袖 vect測 kh存c kh束ng.T測ng 淡ng v鱈i m辿t gi存 tr ri捉ng c達 v束 s竪 vect測
ri捉ng.Nu X l袖 m辿t vc t測 ri捉ng t測ng 淡ng v鱈i gi存 tr ri捉ng 了 th cX c嘆ng l袖 vec t ri捉nh 淡ng
v鱈i 了.C達 nhiu thut to存n tm gi存 tr ri捉ng v袖 vect測 ri捉ng c単a m辿t ma trn.Gi其 s旦 ta c達 ma
trn A,g辰i E l袖 ma trn 速測n v th theo (1) ta c達:
(A-了E)X = 0 (2)
v袖 (A - 了E) l袖 ma trn c達 d孫ng:

















了
了
了
aaa
.......
aaa
aaa
nn2n1n
n22221
n11211
....
....
....
(3)
Nh vy do (2) l袖 h ph測ng trnh tuyn tnh thun nht n捉n 速iu kin cn v袖 速単 速 了
l袖 gi存 tr ri捉ng c単a ma trn tr捉n l袖 速nh th淡c c単a n達 b損ng kh束ng:
det(A - 了E) = 0 (4)
Ph測ng trnh (4) 速樽c g辰i l袖 ph測ng trnh 速c trng c単a ma trn A.則nh th淡c det(A - 了E)
速樽c g辰i l袖 速nh th淡c 速c trng c単a ma trn A.則nh th淡c PA(了) c単a ma trn tr捉n 速樽c g辰i l袖
速a th淡c 速c trng c単a ma trn vu束ng A.
V d担 tm vec t測 ri捉ng v袖 tr ri捉ng c単a ma trn:











022
113
313
Tr鱈c ht ta tnh 速a th淡c 速c trng c単a ma trn A:
127
)4()4(
22
113
313
)(P
2
A
+










了了=
了
了
了
=了
Nghim c単a PA(了) = 0 l袖 了1 = 4,了2 = 2j v袖 了3 = -2j.V tr棚ng c測 s谷 l袖 s竪 th湛c n捉n ta ch ly 了
= 4.則 tm vec t測 ri捉ng t測ng 淡ng v鱈i 了 = 4 ta gi其i h
0
22
113
313
3
2
1
=


















両
両
両

了
了
了
ta nhn 速樽c c存c gi存 tr c単a 両,ch坦ng t孫o th袖nh vec t測 ri捉ng 淡ng v鱈i 了.
Nh vy khi khai trin 速nh th淡c ta c達 m辿t 速a th淡c bc n c達 d孫ng:
Pn(了) = 了n
- p1了n-1
- p2了n-2
- - pn = 0
Mu竪n x存c 速nh c存c h s竪 c単a 速a th淡c 速c tnh n袖y ta d誰ng ph測ng ph存p Fadeev-Leverrier.Ta
xt ma trn A:














=
nn2n1n
n22221
n11211
aaa
aaa
aaa
A
Ta g辰i vt c単a ma trn A l袖 s竪:
vet(A)= a11 + a22 +...+ ann
Khi 速達 tham s竪 pi c単a Pn(了) 速樽c c存c 速nh nh sau:
p1 = vet(B1) v鱈i B1 = A
p2 = (1/2)vet(B2) v鱈i B2 = A(B1-p1E)
p3 = (1/3)vet(B3) v鱈i B3 = A(B2-p2E)
......
Ch測ng trnh tnh c存c h s竪 pi nh sau:
Ch測ng trnh 9-4
// Faddeev_Leverrier;
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#define max 50
void main()
{
int i,j,k,m,n,k1,t;
float vet,c1,d;
char tl;
float p[max];
float a[max][max],b[max][max],c[max][max],b1[max][max];
clrscr();
printf("Cho bac cua ma tran n = ");
scanf("%d",&n);
printf("Cho cac phan tu cua ma tran a : n");
128
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
{
printf("a[%d][%d] = ",i,j );
scanf("%f",&a[i][j]);
}
printf("n");
clrscr();
printf("Ma tran ban da nhap");
printf("n");
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
printf("%10.5f",a[i][j]);
printf("n");
}
t=1;
flushall();
while (t)
{
printf("n");
printf("Co sua ma tran khong(c/k)?");
scanf("%c",&tl);
if (toupper(tl)=='C')
{
printf("Cho chi so hang can sua : ");
scanf("%d",&i);
printf("Cho chi so cot can sua : ");
scanf("%d",&j);
printf("a[%d][%d] = ",i,j);
scanf("%f",&a[i][j]);
flushall();
}
if (toupper(tl)=='K')
t=0;
}
printf("Ma tran ban dau");
printf("n");
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
printf("%10.5f",a[i][j]);
printf("n");
}
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
b[i][j]=a[i][j];
for (k=1;k<=n-1;k++)
{
vet=0.0;
129
for (i=1;i<=n;i++)
vet+=b[i][i];
p[k]=vet/k;
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
{
if (j!=i)
c[i][j]=b[i][j];
if (j==i)
c[i][j]=b[i][j]-p[k];
}
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
{
b[i][j]=0.0;
for (k1=1;k1<=n;k1++)
b[i][j]+=a[i][k1]*c[k1][j];
}
}
vet=0.0;
for (i=1;i<=n;i++)
vet+=b[i][i];
p[n]=vet/n;
printf("n");
printf("Cac he so cua da thuc dac trungn");
printf("n");
d=1.0;
printf("%6.2f",d);
for (i=1;i<=n;i++)
{
c1=-p[i];
printf("%5c%6.2f",' ',c1);
}
getch();
}
2.Ph測ng ph存p Mises: Thut to存n Mises tm gi存 tr ri捉ng l鱈n nht c単a m辿t ma trn A. Nu
ma trn A l袖 th湛c v袖 v袖 m巽i tr ri捉ng b辿i k c達 速単 k vec t測 ri捉ng 速辿c lp tuyn tnh th vic
tnh to存n s cho ta gi存 tr ri捉ng l鱈n nht.
M辿t vect測 V bt k c達 th 速樽c vit d鱈i d孫ng:

=
=+++=
n
1i
iinn2211 XvXvXvXvV (5)
Trong 速達 X1,X2,..,Xn l袖 c存c vec t測 ri捉ng t測ng 淡ng v鱈i c存c gi存 tr ri捉ng 了1,了2,了3,..,了n
v袖 v1,v2,v3,...,vn l袖 c存c h損ng s竪.
Khi nh息n A v鱈i V ta c達:
AV = Av1X1 + Av2X2 +....+ AvnXn
do: Av1X1 = v1AX1 = v1了1X1 ; Av2X2 = v2AX2 = v2了2X2 v.v.
Vy n捉n: AV = v1了1X1 + v2了2X2 +...+ vn了nXn
130
XvXAvAV ii
n
1i
iii
n
1i
i 了
==
==
L孫i nh息n biu th淡c tr捉n v鱈i A ta c達:
A2
V = v1了1 AX1 + v2了2 AX2 +...+ vn了n AXn
= v1了2
1X1 + v2了2
2
X2 +...+ vn了n
2
Xn
v袖 tip 速n ln th淡 p ta c達:
XvXvXvXvVA n
p
nn2
p
211
p
11i
p
i
n
1i
i
p
了了了了 +++==
=
Ly 了p
1 l袖m th探a s竪 chung ta c達:
・
・
ヲ
、
「
「
」
。






了
了
++





了
了
+





了
了
+了= n
p
1
n
n3
p
1
3
32
p
1
2
211
p
1
p
XvXvXvXvVA
T測ng t湛 ta c達:
・
・
ヲ
、
「
「
」
。






了
了
++





了
了
+





了
了
+了=
+++
++
n
1p
1
n
n3
1p
1
3
32
1p
1
2
211
1p
1
1p
XvXvXvXvVA
Khi p rt l鱈n,v 了1 > 了2 > 了3 >,...,了n n捉n:






了
了
pkhi0
1
i
Do 速達: 11
p
1
p
p
XvVAlim 了=

(6)
11
1p
1
1p
p
XvVAlim ++

了=
ngha l袖 khi p 速単 l鱈n th:
11
p
1
p
XvVA 了=
11
1p
1
1p
XvVA ++
了=
do 速達: VAVA p
1
1p
了=+
hay: ( ) VAVAA p
1
p
了=
Nh vy VAp l袖 vc t測 ri捉ng c単a A 淡ng v鱈i 了1 cn gi存 tr ri捉ng 了1 s l袖:
1p
1p
p VA
VA
lim 了=
+

Trong th湛c t 速 tr存nh v樽t qu存 dung l樽ng b辿 nh鱈 khi 了1 kh存 l鱈n,c存c vect測 Vk 速樽c
chun ho存 sau m巽i b鱈c b損ng c存ch chia c存c phn t旦 c単a n達 cho phn t旦 l鱈n nht mk v袖 nhn
速樽c vect測 V
k
Nh vy c存c b鱈c tnh s l袖:
- cho m辿t vec t測 V bt k (c達 th l袖 V = { 1,1,1,...,1}T
)
- tnh V1 = AV v袖 nhn 速樽c phn t旦 l鱈n nht l袖 m1j t探 速達 tnh tip V
1 = V1/m1j
M辿t c存ch t脱ng qu存t,t孫i ln lp th淡 p ta nhn 速樽c vect測 Vp v袖 phn t旦 l鱈n nht mpj th
V
p = Vp/ mpj.
- tnh p1p VAV =+ v鱈i vp+1,j l袖 phn t旦 th淡 j c単a Vp+1.Ta c達:
ェゥ
ェ
ィ
ァ
了=
=
+


1j,1p
p
1p
p
vlim
XVlim
V d担: Tm gi存 tr ri捉ng l鱈n nht v袖 vec t測 ri捉ng t測ng 淡ng c単a ma trn:
131











=
26544323
68102
720138
17302417
A
Ch辰n V= {1,1,1,1}T
ta tnh 速樽c
V V1 = AV V1 V2 =
AV1
V2
1 88 -0.6027 -6.4801 -0.5578
1 48 -0.3288 -5.6580 -0.4870
1 26 -0.1781 0.0818 0.0070
1 -146 1 11.6179 1
了 11.6179
V3 =
AV2
V3 V4 = AV3 V4 V5 =
AV4
-3.9594 -0.5358 -3.6823 -0.5218 -3.5718
-3.6526 -0.4942 -3.5196 -0.4987 -3.4791
0.0707 0.0096 0.0630 0.0089 0.0408
7.3902 1 7.0573 1 6.9638
了 7.3902 7.0573 6.9638
V5 V6=
AV5
V6 V7= AV6 V7
-
0.5129
-3.5341 -0.5075 -3.5173 -0.5043
-
0.4996
-3.4809 -0.4999 -3.4868 -0.5000
0.0059 0.0250 0.0036 0.0147 0.0021
1 6.9634 1 6.9742 1
了 6.9634 6.9742
D誰ng thut to存n tr捉n ta c達 ch測ng trnh sau:
Ch測ng trnh 9-5
#include <conio.h>#include <stdio.h>#include <math.h>#include <stdlib.h>#include
<ctype.h>#define max 50void main() { int i,j,k,n,t; char tl; float t0,t1,epsi,s;
float a[max][max];
float x0[max],x1[max];
clrscr();
printf("Phuong phap lap luy thua tim tri rieng lon nhatn");
printf("Cho so hang va cot cua ma tran n = ");
scanf("%d",&n);
printf("Cho cac phan tu cua ma tran a : n");
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
132
{
printf("a[%d][%d] = ",i,j);
scanf("%f",&a[i][j]);
}
printf("n");
printf("Ma tran ban da nhapn");
printf("n");
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
printf("%15.5f",a[i][j]);
printf("n");
}
flushall();
t=1;
while (t)
{
printf("nCo sua ma tran khong(c/k)?");
scanf("%c",&tl);
if (toupper(tl)=='C')
{
printf("Cho chi so hang can sua : ");
scanf("%d",&i);
printf("Cho chi so cot can sua : ");
scanf("%d",&j);
printf("a[%d][%d] = ",i,j);
scanf("%f",&a[i][j]);
}
if (toupper(tl)=='K')
t=0;
}
epsi=1e-5;
printf("nMa tran ban daun");
printf("n");
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
printf("%15.5f",a[i][j]);
printf("n");
}
printf("n");
for (i=1;i<=n;i++)
x0[i]=1;
k=1;
t=0;
t1=0;
do
{
t0=t1;
for (i=1;i<=n;i++)
133
{
x1[i]=0;
for (j=1;j<=n;j++)
x1[i]=x1[i]+a[i][j]*x0[j];
}
s=0;
j=0;
for (i=1;i<=n;i++)
if (s<fabs(x1[i]))
{
j=i;
s=fabs(x1[i]);
}
t1=x1[j];
for (i=1;i<=n;i++)
x1[i]=x1[i]/t1;
if (fabs(t1-t0)<epsi)
{
printf("Da thuc hien %d buoc lapn",k);
printf("Gia tri rieng lon nhat Vmax = %15.5fn",t1);
printf("Vec to rieng tuong ungn");
for (i=1;i<=n;i++)
printf("%.5fn",x1[i]);
t=1;
}
if (fabs(t1-t0)>epsi)
{
for (i=1;i<=n;i++)
x0[i]=x1[i];
k=k+1;
}
if (k>max)
t=1;
}
while(t==0);
getch();
}
D誰ng ch測ng trnh n袖y tnh ga tr ri捉ng v袖 vec t測 ri捉ng c単a ma trn:










308
649
012
ta nhn 速樽c gi存 tr ri捉ng l袖 3.0000 v袖 vec t測 ri捉ng l袖 x = { -0.75 ; 0.75 ; 1 }T
Nh ch坦ng ta 速揃 n達i tr鱈c 速息y,ph測ng ph存p Mises (hay cn g辰i l袖 ph測ng ph存p lp
l嘆y th探a) ch cho php tm gi存 tr ri捉ng l鱈n nht v袖 vec t測 ri捉ng t測ng 淡ng c単a ma trn.則
x存c 速nh c存c gi存 tr ri捉ng kh存c,ma trn A 速樽c bin 速脱i th袖nh m辿t ma trn kh存c A1 m袖 c存c
gi存 tr ri捉ng l袖 了2 > 了3 >...> 了n.Ph測ng ph存p n袖y g辰i l袖 ph測ng ph存p xu竪ng thang.Sau 速息y l袖
ph測ng ph存p bin 速脱i ma trn:
134
Gi其 s旦 X1 l袖 vec t測 ri捉ng c単a ma trn A t測ng 淡ng v鱈i gi存 tr ri捉ng 了1 v袖 W1 l袖 vec t測
ri捉ng c単a ma trn AT
t測ng 淡ng v鱈i gi存 tr ri捉ng 了1.T探 速nh ngha AX1 = 了1X1 ta vit:
(A - 了E)X1 = 0
Ta t孫o ma trn A1 d孫ng:
WX
XW
AA
T
11
1
T
1
1
1
了=
(7)
Ta ch坦 箪 l袖 X1W1
T
l袖 m辿t ma trn cn W1
T
X1 l袖 m辿t con s竪.Khi nh息n hai v c単a biu th淡c
(7) v鱈i X1 v袖 ch箪 箪 速n tnh kt h樽p c単a tch c存c ma trn ta c達:
0
XAX
XW
XW
XAX
XWX
XW
AXXA
111
1
T
1
1
T
1
111
1
T
11
1
T
1
1
111
=
=
=
=
了
了
了
(8)
A1 chp nhn gi存 tr ri捉ng b損ng kh束ng.
Nu X2 l袖 vec t測 ri捉ng t測ng 淡ng v鱈i gi存 tr ri捉ng 了2,th khi nh息n A1 v鱈i X2 ta c達:
XW
XW
XAX
XWX
XW
AXXA
1
T
1
2
T
1
112
2
T
11
1
T
1
1
221
了
了
=
= (9)
Theo 速nh ngha v W1 l袖 vect測 ri捉ng c単a AT
n捉n:
了1W1 =AT
W1 (10)
Mt kh存c do:
(AX)T
=XT
AT
v袖 (AT
)T
= A
N捉n khi chuyn v (10) ta nhn 速樽c:
(AT
W1)T
= 了1WT
1
Hay:
W1
T
A = 了1W1
T
(11)
Khi nh息n (11) v鱈i X2 ta c達:
了1W1
T
X2 = W1
T
AX2
v袖 do 速nh ngha:
AX2 = 了2X2
n捉n:
了1W1
T
X2 = W1
T
了2X2
vy th:
(了1 - 了2) W1
T
X2 = 0
khi 了1  了2 th:
W1
T
X2 = 0 (12)
Cu竪i c誰ng thay (12) v袖o (9) ta c達:
A1X2 = AX2 = 了2X2
Nh vy 了2 l袖 gi存 tr ri捉ng l鱈n nht c単a ma trn A1 v袖 nh vy c達 th 存p d担ng thut
to存n n袖y 速 tm c存c gi存 tr ri捉ng cn l孫i c単a ma trn.C存c b鱈c tnh to存n nh sau
- khi 速揃 c達 了1 v袖 X1 ta tm W1 l袖 vec t測 ri捉ng c単a AT
淡ng v鱈i gi存 tr ri捉ng 了1 (v d担 tm
W1 b損ng c存ch gi其i ph測ng trnh (AT
-了1E)W1 = 0).T探 速達 tnh ma trn A12 theo (7).
- tm gi存 tr ri捉ng v袖 vec t測 ri捉ng c単a A1 b損ng c存ch lp c束ng sut v袖 c淡 th tip t担c v袖
xu竪ng thang (n-1) ln ta tm 速単 n gi存 tr ri捉ng c単a ma trn A.
V d担: Tm gi存 tr ri捉ng v袖 vect測 ri捉ng c単a ma trn sau:
135











=
26544323
68102
720138
17302417
A
Ta 速揃 tm 速樽c gi存 tr ri捉ng l鱈n nht 了1 = 7 v袖 m辿t vect測 ri捉ng t測ng 淡ng:
X1 = { 1,1,0,-2}T
.
Ma trn AT
c達 d孫ng:














=
266717
5482030
43101324
232817
A
T
v袖 theo ph測ng trnh AT
-了1E)W1 = 0 ta tm 速樽c vect測 W1 = {293,695,746,434}T
Ta lp ma trn m鱈i A1 theo (7):











=了
86814921390586
0000
434746695293
434746695293
120
7
XW
WX
1
T
1
T
11
1
v袖:












=
6333.240333.330833.381833.11
68102
3167.185167.235417.270917.9
3167.85167.135417.160917.0
A1
T探 ma trn A1 ta tm tip 速樽c 了2 theo php lp lu端 th探a v袖 sau 速達 l孫i tm ma trn A3 v袖 tm
gi存 tr ri捉ng t測ng 淡ng.
Ch測ng trnh lp tm c存c gi存 tr ri捉ng v袖 vec t測 ri捉ng c単a ma trn nh sau:
Ch測ng trnh 9-6
#include <conio.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#define max 50
void main()
{
float a[max][max],vv[max][max],at[max][max];
float x[max],y[max],vd[max];
int i,j,k,n,l,t;
float vp,v1,z,epsi,va,ps;
char tl;
clrscr();
epsi=0.000001;
printf("Cho bac cua ma tran n = ");
scanf("%d",&n);
printf("Cho cac phan tu cua ma tran a : n");
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
136
{
printf("a[%d][%d] = ",i,j);
scanf("%f",&a[i][j]);
}
printf("n");
clrscr();
printf("Ma tran ban da nhap");
printf("n");
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
printf("%15.5f",a[i][j]);
printf("n");
}
t=1;
flushall();
while (t)
{
printf("n");
printf("Co sua ma tran khong(c/k)?");
scanf("%c",&tl);
if (toupper(tl)=='C')
{
printf("Cho chi so hang can sua : ");
scanf("%d",&i);
printf("Cho chi so cot can sua : ");
scanf("%d",&j);
printf("a[%d][%d] = ",i,j);
scanf("%f",&a[i][j]);
}
if (toupper(tl)=='K')
t=0;
}
for (l=1;l<=n;l++)
{
for (i=1;i<=n;i++)
x[i]=1;
vp=1.23456789;
k=0;
for (k=1;k<=40;k++)
{
for (i=1;i<=n;i++)
{
y[i]=0;
for (j=1;j<=n;j++)
y[i]=y[i]+a[i][j]*x[j];
}
v1=y[1]/x[1];
z=0;
for (i=1;i<=n;i++)
137
if (fabs(y[i])>z)
z=y[i];
for (i=1;i<=n;i++)
x[i]=y[i]/z;
if (fabs(vp-v1)<epsi)
break;
vp=v1;
}
{
printf("Gia tri rieng : %9.6fn",v1);
printf("Vec to rieng : n");
for (i=1;i<=n;i++)
printf("%.5fn",x[i]);
printf("n");
getch();
}
vd[l]=v1;
va=v1;
for (i=1;i<=n;i++)
vv[l][i]=x[i];
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
at[i][j]=a[j][i];
for (i=1;i<=n;i++)
x[i]=1;
vp=1.23456;
k=0;
for (k=1;k<=40;k++)
{
for (i=1;i<=n;i++)
{
y[i]=0;
for (j=1;j<=n;j++)
y[i]=y[i]+at[i][j]*x[j];
}
v1=y[1]/x[1];
z=0;
for (i=1;i<=n;i++)
if (fabs(y[i])>z)
z=y[i];
for (i=1;i<=n;i++)
x[i]=y[i]/z;
if (fabs(vp-v1)<epsi)
break;
vp=v1;
}
if (fabs(vp-v1)>epsi)
{
printf("Khong hoi tu sau 40 lan lapn");
getch();
138
exit(1);
}
if (fabs(va-v1)>3*epsi)
{
printf("Co loin");
getch();
exit(1);
}
ps=0;
for (i=1;i<=n;i++)
ps=ps+x[i]*vv[l][i];
ps=v1/ps;
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
a[i][j]=a[i][j]-ps*vv[l][i]*x[j];
}
}
139
Do (6) 速坦ng v鱈i m辰i n n捉n cho n = 1 , 2 , 3 , . . . ta c達 :
| x2 - x1 |  q | x1 - xo |
| x3 - x2 |  q | x2 - x1 |
. . . . . . . . . . . . . . . . . . .
| xn+1 - xn |  q | xn - xn-1 |
則iu n袖y c達 ngha l袖 d揃y xi+1 - xi , m辿t c存ch gn 速坦ng,l袖 m辿t cp s竪 nh息n . Ta
c嘆ng coi r損ng d揃y xn - y v鱈i y l袖 nghim 速坦ng c単a (1) , gn 速坦ng nh- m辿t cp s竪 nh息n c達
c束ng sai q . Nh- vy :
1q
yx
yx
n
1n
<=

+
(7)
hay : )yx(qyx n1n =+ (8)
T-測ng t湛 ta c達 : )yx(qyx 1n2n = ++ (9)
T探 (8) v袖 (9) ta c達 :
n1n
1n2n
xx
xx
q


=
+
++
(10)
Thay gi存 tr c単a q v探a tnh 谷 (10) v袖o biu th淡c c単a q 谷 tr捉n ta c達 :
( )
1n1nn
2
1nn
n
xx2x
xx
xy
++
+
+

= (11)
C束ng th淡c (11) 速-樽c g辰i l袖 c束ng th淡c ngo孫i suy Adam.Nh- vy theo (11) tr-鱈c ht ta d誰ng
ph-測ng ph存p lp 速 tnh gi存 tr gn 速坦ng xn+2,xn+1,xn c単a nghim v袖 sau 速達 theo (11)
tm 速-樽c nghim v鱈i sai s竪 nh叩 h測n.
則 l袖m v d担 ch坦ng ta xt ph-測ng trnh :
lnx - x2
+ 3 = 0
Ta 速-a v d孫ng lp :
3)xln(x +=
3xlnx2
1
)x(f
+
=
Php lp h辿i t担 trong 速o孫n [0.3,].Ta cho x1 = 1 th tnh 速-樽c :
x2 = 1,7320508076
x3 = 1.883960229
x4 = 1.90614167
y = 1.909934347
則 gi其m sai s竪 ta c達 th lp nhiu ln
Ch測ng trnh 8-9
//phuong phap Aitken
#include <conio.h>
#include <stdio.h>
#include <math.h>
#define m 5
void main()
{
140
float x[m];
float epsi,n,y;
int i,z;
float f(float);
clrscr();
printf("Cho tri so ban dau x[1] = ");
scanf("%f",&x[1]);
printf("Cho tri so sai so epsilon = ");
scanf("%f",&epsi);
printf("n");
printf( "Ngoai suy Aitken cua hamn");
z=0;
while (z<=20)
{
for (i=2;i<=4;i++)
x[i]=f(x[i-1]);
n=x[4]-2*x[3]+x[2];
if ((fabs(n)<1e-09)||(fabs(x[1]-x[2])<epsi*fabs(x[1])))
z=20;
else
{
y=x[2]-(x[3]-x[2])*(x[3]-x[2])/n;
if (z>20)
printf("Khong hoi tu sau hai muoi lan lapn");
x[1]=y;
}
z=z+1;
}
printf("Nghiem cua phuong trinh y = %.6f",y);
getch();
}
float f(float x)
{
float s=sqrt(log(x)+3);
return(s);
}
V鱈i gi存 tr ban 速u l袖 1 v袖 sai s竪 l袖 1e-8,ch-測ng trnh cho kt qu其 y = 1.9096975944
則10.Ph測ng ph存p Bairstow
Nguy捉n t他c c単a ph-測ng ph存p Bairstow l袖 trch t探 速a th淡c Pn(x) m辿t tam th淡c Q2(x)
= x2
- sx + p m袖 ta c達 th tnh nghim th湛c hay nghim ph淡c c単a n達 m辿t c存ch 速測n gi其n
b損ng c存c ph-測ng ph存p 速揃 bit.
Vic chia 速a th淡c Pn(x) cho tam th淡c Q2(x) 速-a t鱈i kt qu其 :
Pn(x) = Q2(x).Pn-2(x) + R1(x)
v鱈i Pn(x) = aoxn
+ a1xn-1
+ a2xn-2
+...+ an
141
Q2(x) = x2
- sx + p
Pn-2(x) = boxn-2
+ b1xn-3
+ b2xn-4
+...+ bn-2
R1(x) = 留x + 硫
則 c達 速-樽c m辿t th-測ng 速坦ng,cn tm c存c gi存 tr c単a s v袖 p sao cho R1(x) = 0
(ngha l袖 留 v袖 硫 trit ti捉u).V鱈i s v袖 p 速揃 cho,c存c h s竪 b c単a 速a th淡c Pn-2(x) v袖 c存c h s竪
留 v袖 硫 速-樽c tnh b損ng ph-測ng ph存p truy h奪i.C存c c束ng th淡c nhn 速-樽c khi khai trin biu
th淡c Pn(x) = Q2(x).Pn-2(x) + R1(x) v袖 s他p xp l孫i c存c s竪 h孫ng c誰ng bc :
aoxn
+ a1xn-1
+ a2xn-2
+...+ an = (x2
- sx + p)( boxn-2
+ b1xn-3
+ b2xn-4
+...+ bn-2)
S竪 h孫ng bc H s竪 c単a Pn(x) H s竪 c単a Q2(x).Pn-2(x)
xn
ao bo
xn-1
a1 b1 - sbo
xn-2
a2 b2 - sb1 + pbo
...... ...... .....
xn-k
ak bk - sbk-1 + pbk-2
x an-1 留 - sbn-2 + pbn-3
xo
an 硫 + pbn-2
Nh- vy : bo = a o (1)
b1 = a1 + sbo
b2 = a2 + sb1 - pbo
..................
bk = ak + sbk-1 - pbk-2
留 = an-1 + sbn-2 - pbn-3
硫 = an - pbn-2
Ch坦ng ta nhn thy r損ng 留 速-樽c tnh to存n xut ph存t t探 c誰ng m辿t c束ng th淡c truy h奪i
nh- c存c h s竪 bk v袖 t-測ng 淡ng v鱈i h s竪 bn-1
bn-1 = an-1 + sbn-2 - pbn-3 = 留
H s竪 bn l袖 :
bn = an + sbn-1 - pbn-2 = sbn-1 + 硫
v袖 cu竪i c誰ng :
R1(x) = 留x + 硫 = bn-1(x - s) + bn
Ngo袖i ra c存c h s竪 bi ph担 thu辿c v袖o s v袖 p v袖 b息y gi棚 ch坦ng ta cn ph其i tm c存c
gi存 tr 速c bit s*
v袖 p*
速 cho bn-1 v袖 bn trit ti捉u.Khi 速達 r1(x) = 0 v袖 nghim c単a tam
th淡c x2
- s*
x + p*
x s l袖 nghim c単a 速a th淡c Pn(x).Ta bit r損ng bn-1 v袖 bn l袖 h袖m c単a s v袖
p :
bn-1 = f(s,p)
bn = g(s,p)
Vic tm s*
v袖 p*
速-a 速n vic gi其i h ph-測ng trnh phi tuyn:
ゥ
ィ
ァ
=
=
0)p,s(g
0)p,s(f
Ph-測ng trnh n袖y c達 th gi其i d d袖ng nh棚 ph-測ng ph存p Newton.Tht vy v鱈i m辿t
ph-測ng trnh phi tuyn ta c達 c束ng th淡c lp :
xi+1 = xi - f(xi)/f'(xi)
hay f'(xi)(xi+1 - xi) = -f(xi)
V鱈i m辿t h c達 hai ph-測ng trnh,c束ng th淡c lp tr谷 th袖nh:
142
J(Xi)(Xi+1 - Xi) = -F(Xi)
v鱈i Xi = { si,pi}T
v袖 Xi+1 = { si+1,pi+1}T
)p,s(g
)p,s(f
)X(F
ii
ii
i =
i
J X
f
s
f
p
g
s
g
p
( )=








Quan h : J(Xi)X = -F(Xi) v鱈i X = {si+1 - si,pi+1 - pi}T
t-測ng 淡ng v鱈i m辿t h ph-測ng trnh
tuyn tnh hai n s竪 s = si+1 - si v袖 p = pi+1 - pi :








f
s
s
f
p
p f s p
g
s
s
g
p
p g s p
i i
i i
 
 
+ =
+ =
ァ
ィ
ェ
ェ
ェ
ゥ
ェ
ェ
ェ


( )
( )
,
,
Theo c束ng th淡c Cramer ta c達 :
s
f
g
p
g
f
p
=
 +




隆
p
g
f
s
f
g
s=
 +




隆
隆








= 
f
s
g
p
f
p
g
s
則 d誰ng 速-樽c c束ng th淡c n袖y ta cn tnh 速-樽c c存c 速孫o h袖m


f
s
,


f
p
,


g
s
,


g
p
.C存c 速孫o h袖m
n袖y 速-樽c tnh theo c束ng th淡c truy h奪i.
Do bo = ao n捉n
ob
s


=0 ob
p


=0
b1 = a1 + sbo n捉n 1

b
s
bo
= 1
0


b
p
=
b2 = a2 + sb1- pbo n捉n 2 2 1







b
s
a
s
sb
s
pb
s
o
= + 
( ) ( )
Mt kh存c : 2
0


a
s
=
1 1
1




( )sb
s s
b
s b= +
o
pb
s


( )
=0
n捉n :
2
1


b
s
b sbo
= +
b3 = a3 + sb2- pb1 n捉n
3
2
2 1





b
s
b s
b
s
p b
s
= + 
Nu ch坦ng ta 速t :
k
k
b
s c


= 1
143
th : co = bo (2)
c1 = b1 + sbo = b1 + sco
c2 = b2 + sc1 - pco
....................
ck = bk + sck-1 - pck-2
cn-1 = bn-1 + scn-2 - pcn-3
Nh- vy c存c h s竪 c嘆ng 速-樽c tnh theo c存ch nh- c存c h s竪 bk.Cu竪i c誰ng v鱈i f = bn-1 v袖 g = bn
ta 速-樽c:
2n1n3n2n c
s
f
c
s
f
c
s
f
c
s
f
 =


=


=


=


2
2n3n1n
3nn2n1n
ccc
cbcb
s




= (3)
2
2n3n1n
2nn1n1n
ccc
cbcb
p




= (4)
Sau khi ph息n tch xong Pn(x) ta tip t担c ph息n tch Pn-2(x) theo ph-測ng ph存p tr捉n
C存c b-鱈c tnh to存n g奪m :
- Ch辰n c存c gi存 tr ban 速u bt k s0 v袖 p0
- Tnh c存c gi存 tr bo,..,bn theo (1)
- Tnh c存c gi存 tr co,...,cn theo (2)
- Tnh so v袖 po theo (3) v袖 (4)
- Tnh s1 = s0 + so v袖 p1 = po+ po
- Lp l孫i b-鱈c 1 cho 速n khi pi+1 = pi = p v袖 si+1 = si = s
- Gi其i ph-測ng trnh x2 - sx + p 速 tm 2 nghim c単a 速a th淡c
- B他t 速u qu存 trnh tr捉n cho 速a th淡c Pn-2(x)
V d担 : Tm nghim c単a 速a th淡c P4(x) = x4
- 1.1x3
+ 2.3x2
+ 0.5x2
+ 3.3.
V鱈i ln lp ban 速u ta ch辰n s = -1 v袖 p =1,ngha l袖 tam th淡c c達 d孫ng x2
+ x + 1
a0 a1 a2 a3 a4
1 -1.1 2.3 0.5 3.3
sbi -1 2.1 -3.4 0.8
-pbi-1 -1 2.1 -3.4
bi 1 -2.1 3.4 -0.8 = bn-1 0.7=bn
sbi -1.0 3.1 -5.5
-pbi-1 -1.0 3.1
ci 1 -3.1 5.5 -3.2
11.0
5.52.3
1.35.5
5.57.0
1.38.0
s =




=
06.0
5.52.3
1.35.5
7.02.3
8.05.5
p =



=
144
s*
= -1 + 0.11 = -0.89
p*
= 1 + 0.06 = 1.06
Tip t担c lp ln 2 v鱈i s1 = s*
v袖 p1 = p*
ta c達 :
a0 a1 a2 a3 a4
1 -1.1 2.3 0.5 3.3
sbi -0.89 1.77 -2.68 0.06
-pbi-1 -1.06 2.11 -3.17
bi 1 -1.99 3.01 -0.07 = bn-1 0.17=bn
sbi -0.89 2.56 -4.01
-pbi-1 -1.0 3.1
ci 1 -2.88 4.51 -1.03
01.0
51.403.1
88.251.4
5.57.0
88.207.0
s =




=
04.0
51.403.1
88.251.4
17.003.1
07.051.4
p =



=
s*
= -0.89 - 0.01 = -0.9
p*
= 1.06 + 0.04 = 1.1
Nh- vy P4(x) = (x2
+0.9x+1.1)(x2
+ 2x+3)
Ch-測ng trnh sau 存p d担ng l thuyt v探a n捉u 速 tm nghim c単a 速a th淡c.
Ch測ng trnh 8-10
//phuong phap Bairstow
#include <conio.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define m 10
void main()
{
float a[m],b[m],c[m];
int i,n,v;
float s,e1,t,p,q,r,p1,q1;
clrscr();
printf("Cho bac cua da thuc n = ");
scanf("%d",&n);
printf("Cho cac he so cua da thuc can tim nghiemn");
for (i=n;i>=0;i--)
{
145
printf("a[%d] = ",n-i);
scanf("%f",&a[i]);
}
printf("n");
e1=0.0001;
if (n<=2)
if (n==1)
{
printf("Nghiem cua hen");
printf("%.8f",(a[0]/(-a[1])));
getch();
exit(1);
}
do
{
v=0;
p=1;
q=-1;
b[n]=a[n];
c[n]=a[n];
do
{
b[n-1]=b[n]*p+a[n-1];
c[n-1]=b[n-1]+b[n]*p;
for (i=n-2;i>=0;i--)
{
b[i]=b[i+2]*q+b[i+1]*p+a[i];
c[i]=c[i+2]*q+c[i+1]*p+b[i];
}
r=c[2]*c[2]-c[1]*c[3];
p1=p-(b[1]*c[2]-b[0]*c[3])/r;
q1=q-(b[0]*c[2]-b[1]*c[1])/r;
if ((fabs(b[0])<e1)&&(fabs(b[1])<e1))
goto tt;
v=v+1;
p=p1;
q=q1;
}
while (v<=40);
if(v>40)
{
printf("Khong hoi tu sau 40 lan lap");
getch();
exit(1);
}
tt:s=p1/2;
t=p1*p1+4*q1;
if(t<0)
{
printf("Nghiem phucn");
146
printf("%.8f+%.8fjn",s,(sqrt(-t)/2));
printf("%.8f-%.8fjn",s,(sqrt(-t)/2));
printf("n");
}
else
{
printf("Nghiem thucn");
printf("%.8fn",(s+sqrt(t)/2));
printf("%.8fn",(s-sqrt(t)/2));
printf("n");
}
for (i=2;i<=n;i++)
a[i-2]=b[i];
n=n-2;
}
while ((n>2)&(r!=0.0));
s=-a[1]/(2*a[2]);
t=a[1]*a[1]-4*a[2]*a[0];
if (t<0)
{
printf("Nghiem phucn");
printf("%.8f+%.8fjn",s,(sqrt(-t)/(2*a[2])));
printf("%.8f-%.8fjn",s,(sqrt(-t)/(2*a[2])));
printf("n");
}
else
{
printf("Nghiem thucn");
printf("%.8fn",(s-sqrt(t)/(2*a[2])));
printf("%.8fn",(s-sqrt(t)/(2*a[2])));
printf("n");
}
getch();
}
D誰ng ch-測ng trnh tr捉n 速 x存c 速nh nghim c単a 速a th淡c :
x6
- 2x5
- 4x4
+ 13x3
- 24x2
+ 18x - 4 = 0
ta nhn 速-樽c c存c nghim :
x1 = 2.61903399
x2 = -2.73205081
x3 = 0.732050755
x4 = 0.381966055
x5 = 0.500011056 + i*1.3228881
x6 = 0.500011056 - i*1.3228881
則11.H ph測ng trnh phi tuyn
Ph-測ng ph存p Newton c達 th 速-樽c t脱ng qu存t ho存 速 gi其i h ph-測ng trnh phi tuyn
d孫ng :
147
ェ
ェ
ェ
ゥ
ェ
ェ
ェ
ィ
ァ
=
=
=
=
0)x,...,x,x,x(f
...............................
0)x,...,x,x,x(f
0)x,...,x,x,x(f
0)x,...,x,x,x(f
2321n
23213
23212
23211
hay vit g辰n h測n d-鱈i d孫ng :
F(X) = 0
Trong 速達 : X = (x1,x2,x3,.....,xn)
V鱈i m辿t ph-測ng trnh m辿t bin,c束ng th淡c Newton l袖 :
i i
i
i
x x
f x
f x+ = 1
( )
'( )
hay : f'(xi).x = -f(xi)
v鱈i x = xi+1 - xi
則竪i v鱈i h,c束ng th淡c lp l袖 :
J(Xi)x = -F(Xi)
Trong 速達 J(Xi) l袖 to存n t旦 Jacobi.N達 l袖 m辿t ma trn bc n ( n - t-測ng 淡ng v鱈i s竪 th袖nh phn
trong vect測 X) c達 d孫ng :
i
n
n
n n n n
n
J x
f
x
f
x
f
x
f
x
f
x
f
x
f
x
f
x
f
x
f
x
f
x
f
x
( ) .
.
..............
..............
..............
=
1
1
1
2
1
3
1
2
1
2
2
2
3
2
1 2 3
























v袖 X = Xi+1 - Xi
Ph-測ng ph存p Newton tuyn tnh ho存 h v袖 nh- vy v鱈i m巽i b-鱈c lp cn gi其i m辿t
h ph-測ng trnh tuyn tnh (m袖 bin l袖 xi) x存c 速nh b谷i c束ng th淡c lp cho t鱈i khi
vect測 X(x1,x2,x3,.....,xn) gn v鱈i nghim.
D-鱈i 速息y l袖 ch-測ng trnh gi其i h ph-測ng trnh phi tuyn
1
3
2
3
1 2 4
1 2 3 4
1
2
3
1 2 3 4
3 8 0
5 0
25 8 4 0
2 8 0
x x x x x
x x x x
x x
x x x x
  =
+ + +  =
 + + =
 + =
ァ
ィ
ェ
ェ
ェ
ゥ
ェ
ェ
ェ
Ma trn 速孫o h袖m ri捉ng J(xi)l袖 :
1
2
2 4 2
2
1 4 1 2
1
2 3 2 3 2 3
3 3 3 3 0 3
1 1 1 1
25
0 8 0
2 2 2 1
1
2
x x x x x x x x
x
x
x x x x x x
  

























Ma trn n袖y 速-樽c ch-測ng trnh 速辰c v袖o nh棚 th単 t担c doc.Trong th単 t担c n袖y,c存c h s竪 a[i,5]
l袖 c存c h袖m fi(x).Vect測 nghim ban 速u 速-樽c ch辰n l袖 { 0,-1,-1,1}T
.Kt qu其 tnh cho ta : x
= {0.01328676,-1.94647929,-1.12499779,8.05819031 }T
v鱈i 速辿 chnh x存c 0.000001.Vect測
s竪 d- r = { 0.00000536,-0.00000011,-0.00000001,-0.00000006}T
.
148
Ch測ng trnh 8-11
//giai he pt phi tuyen
#include <conio.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define n 4
float a[n+1][n+2];
float x[n+1],y[n+1];
int i,j,k,l,z,r;
float e,s,t;
void main()
{
void doc();
clrscr();
printf("Cho cac gia tri nghiem ban daun");
for (i=1;i<=n;i++)
{
printf("x[%d] = ",i);
scanf("%f",&x[i]);
}
e=1e-6;
z=30;
for (r=1;r<=z;r++)
{
doc();
for (k=1;k<=n-1;k++)
{
s=0 ;
for (i=k;i<=n;i++)
{
t=fabs(a[i][k]);
if (s<=t)
{
s=t;
l=i;
}
}
for (j=k;j<=n+1;j++)
{
s=a[k][j];
a[k][j]=a[l][j];
a[l][j]=s;
}
if (a[1][1]==0)
{
149
printf("Cac phan tu duong cheo cua ma tran bang khong");
getch();
exit(1);
}
else
{
if (fabs(a[k][k]/a[1][1])<(1e-08))
{
printf("Ma tran suy bien");
goto mot;
}
}
for (i=k+1;i<=n;i++)
{
if (a[k][k]==0)
{
printf("Cac phan tu duong cheo cua ma tran bang
khongn");
goto mot;
}
s=a[i][k]/a[k][k];
a[i][k]=0;
for (j=k+1;j<=n+1;j++)
a[i][j]=a[i][j]-s*a[k][j];
}
y[n]=a[n][n+1]/a[n][n];
for (i=n-1;i>=1;i--)
{
s=a[i][n+1];
for (j=i+1;j<=n;j++)
s=s-a[i][j]*y[j];
if (a[i][i]==0)
{
printf("Cac phan tu duong cheo cua ma tran bang
khongn");
goto mot;
}
y[i]=s/a[i][i];
}
}
if (r!=1)
for (i=1;i<=n;i++)
{
if (fabs(y[i])<e*fabs(x[i]))
goto ba;
}
for (i=1;i<=n;i++)
x[i]=x[i]-y[i];
printf("n");
}
150
printf("Khong hoi tu sau %d lan lapn",z);
goto mot;
clrscr();
ba:printf("Vec to nghiemn");
for (i=1;i<=n;i++)
printf("%.5fn",(x[i]-y[i]));
printf("n");
printf("Do chinh xac cua nghiem la %.5f: n", e);
printf("n");
printf("Vec to tri so du :n");
for (i=1;i<=n;i++)
printf("%.5fn",(a[i][n+1]));
mot:printf("n");
getch();
}
void doc()
{
a[1][1]=3*x[1]*x[1]-3*x[2]*x[4];
a[1][2]=-3*x[2]*x[2]-3*x[1]*x[4];
a[1][3]=0;
a[1][4]=-3*x[1]*x[2];
a[1][5]=x[1]*x[1]*x[1]-x[2]*x[2]*x[2]-3*x[1]*x[2]*x[4]-8;
a[2][1]=1;
a[2][2]=1;
a[2][3]=1;
a[2][4]=1;
a[2][5]=x[1]+x[2]+x[3]+x[4]-5;
a[3][1]=-x[1]/sqrt(25-x[1]*x[1]);
a[3][2]=0;
a[3][3]=8;
a[3][4]=0;
a[3][5]=sqrt(25-x[1]*x[1])+8*x[3]+4;
a[4][1]=2*x[2]*x[3];
a[4][2]=2*x[1]*x[3];
a[4][3]=2*x[1]*x[2];
a[4][4]=-1;
a[4][5]=2*x[1]*x[2]*x[3]-x[4]+8;
}

More Related Content

Chuong9

  • 1. 116 Ch測ng 9 : C存c vn 速 v ma trn 則1.則nh th淡c c単a ma trn Cho m辿t ma trn vu束ng cp n.Ta cn tm 速nh th淡c c単a n達.Tr鱈c ht ch坦ng ta nh他c l孫i m辿t s竪 tnh cht quan tr辰ng c単a 速nh th淡c: - nu nh息n tt c其 c存c phn t旦 c単a m辿t h袖ng (hay c辿t) v鱈i k th 速nh th淡c 速樽c nh息n v鱈i k - 速nh th淡c kh束ng 速脱i nu ta c辿ng th捉m v袖o m辿t h袖ng t脱 h樽p tuyn tnh c単a c存c h袖ng cn l孫i. Ta s 存p d担ng c存c tnh cht n袖y 速 tnh 速nh th淡c c単a m辿t ma trn cp 4 nh sau(ph測ng ph存p n袖y c達 th m谷 r辿ng cho m辿t ma trn cp n) b損ng ph測ng ph存p tr担: = 44434241 34333231 24232221 14131211 aaaa aaaa aaaa aaaa A Ly gi存 tr tr担 l袖 p1= a11.Ta chia c存c phn t旦 c単a h袖ng th淡 nht cho p1= a11 th 速nh th淡c s l袖 D/p1 (theo tnh cht 1) v袖 ma trn cn l孫i l袖: 霞霞 44434241 34333231 24232221 141312 aaaa aaaa aaaa aaa1 Ly h袖ng 2 tr探 速i h袖ng 1 速揃 nh息n v鱈i a21,ly h袖ng 3 tr探 速i h袖ng 1 速揃 nh息n v鱈i a31 v袖 ly h袖ng 4 tr探 速i h袖ng 1 速揃 nh息n v鱈i a41 (thay h袖ng b損ng t脱 h樽p tuyn tnh c単a c存c h袖ng cn l孫i) th 速nh th淡c vn l袖 D/p1 v袖 ma trn l袖: 霞霞 霞霞 霞霞 霞霞 444342 343332 242322 141312 aaa0 aaa0 aaa0 aaa1 Ly gi存 tr tr担 l袖 222 ap = .Ta chia c存c phn t旦 c単a h袖ng th淡 hai cho p2 th 速nh th淡c s l袖 D/(p1p2) v袖 ma trn cn l孫i l袖: 霞霞 霞霞 霞霞霞 霞霞 444342 343332 2423 141312 aaa0 aaa0 aa10 aaa1 Ly h袖ng 1 tr探 速i h袖ng 2 速揃 nh息n v鱈i 12a ,ly h袖ng 3 tr探 速i h袖ng 2 速揃 nh息n v鱈i 32a v袖 ly h袖ng 4 tr探 速i h袖ng 2 速揃 nh息n v鱈i 42a th 速nh th淡c vn l袖 D/p1 v袖 ma trn l袖: th 速nh th淡c vn l袖 D/(p1p2) v袖 ma trn l袖:
  • 2. 117 霞霞霞 霞霞霞 霞霞霞 霞霞霞 4443 3433 2423 1413 aa00 aa00 aa10 aa01 Tip t担c ly h袖ng 3 r奪i h袖ng 4 l袖m tr担 th ma trn s l袖: 1000 0100 0010 0001 則nh th淡c c単a ma trn n袖y l袖 D/(p1p2p3p4)= D/( 44332211 aaaa 霞霞霞霞霞 ) =1 n捉n 速nh th淡c c単a ma trn A l袖 D = p1p2p3p4. Sau 速息y l袖 ch測ng trnh tm 速nh th淡c c単a m辿t ma trn: Ch測ng trnh 9-1 //tinh dinh thuc #include <conio.h>#include <stdio.h>#include <ctype.h> #include <stdlib.h> void main() { int i,j,k,n,ok1,ok2,t; float d,c,e,f,g,h; float a[50][50]; char tl; clrscr(); printf("** TINH DINH THUC CAP n **"); printf("n"); printf("n"); printf("Cho cap cua dinh thuc n = "); scanf("%d",&n); printf("Nhap ma tran an"); for (i=1;i<=n;i++) { printf("Dong %d:n",i); for (j=1;j<=n;j++) { printf("a[%d][%d] = ",i,j); scanf("%f",&a[i][j]); } printf("n"); } printf("n"); printf("Ma tran a ma ban da nhapn"); printf("n"); for (i=1;i<=n;i++) { for (j=1;j<=n;j++)
  • 3. 118 printf("%.5ft",a[i][j]); printf("n"); } printf("n"); t=1; flushall(); while (t) { printf("Co sua ma tran a khong(c/k)?"); scanf("%c",&tl); if (toupper(tl)=='C') { printf("Cho chi so hang can sua : "); scanf("%d",&i); printf("Cho chi so cot can sua : "); scanf("%d",&j); printf("a[%d][%d] = ",i,j); scanf("%f",&a[i,j]); } if (toupper(tl)=='K') t=0; } printf("Ma tran a ban daun"); printf("n"); for (i=1;i<=n;i++) { for (j=1;j<=n;j++) printf("%.5ft",a[i][j]); printf("n"); } printf("n"); d=1; i=1; ok2=1; while ((ok2)&&(i<=n)) { if (a[i][i]==0) { ok1=1; k=k+1; while ((ok1)&&(k<=n)) if (a[k,i]!=0) { for (j=i;j<=n;j++) { c=a[i][j]; a[i][j]=a[k][j]; a[k][j]=c; } d=-d;
  • 4. 119 ok1=0; } else k=k+1; if (k>n) { printf("n"); printf("** MA TRAN SUY BIEN **"); ok2=0; d=0; } } if (a[i][i]!=0) { c=a[i][i]; for (j=i+1;j<=n;j++) a[i][j]=a[i][j]/c; for (k=i+1;k<=n;k++) { c=a[k][i]; for (j=i+1;j<=n;j++) a[k][j]=a[k][j]-a[i][j]*c; } } i=i+1; } if (ok2) { for (i=1;i<=n;i++) d=d*a[i][i]; printf("n"); printf("** GIA TRI DINH THUC D **"); printf("n"); printf("%.3f",d); } getch(); } 則2.Nghch 速其o ma trn G辰i A-1 l袖 ma trn nghch 速其o c単a m辿t ma trn A bc n ta c達 AA-1 = E.(trong biu th淡c n袖y E l袖 m辿t ma trn vu束ng c達 c存c phn t旦 tr捉n 速棚ng cho chnh b損ng 1). D孫ng c単a ma trn E,v d担 cp 4,l袖: = 1000 0100 0010 0001 E
  • 5. 120 Ph測ng ph存p lo孫i tr探 速 nhn 速樽c ma trn nghch 速其o A-1 速樽c th湛c hin qua nhiu giai 速o孫n (n),m巽i m辿t giai 速o孫n g奪m hai b鱈c.則竪i v鱈i giai 速o孫n th淡 k: - chun ho存 phn t旦 akk b損ng c存ch nh息n h袖ng v鱈i nghch 速其o c単a n達 - l袖m cho b損ng kh束ng c存c phn t旦 pha tr捉n v袖 pha d鱈i 速棚ng cho cho 速n c辿t th淡 k.Khi k = n th A(k) s tr谷 th袖nh ma trn 速測n v v袖 E tr谷 th袖nh A-1 V d担: Tnh ma trn nghch 速其o c単a ma trn = 211 121 112 A Ta vit l孫i ma trn A v袖 ma trn 速測n v t測ng 淡ng v鱈i n達 = = 100 010 001 E 211 121 112 A Giai 速o孫n 1: B鱈c a: Nh息n h袖ng 1 v鱈i 1/a11,ngha l袖 a, 1j = a1j/a11 速竪i v鱈i dng th淡 nht,a, ij = aij 速竪i v鱈i c存c dng kh存c = = 100 010 0021 E 211 121 21211 A B鱈c b: Tr探 h袖ng 3 v袖 h袖ng 2 cho h袖ng 1,ngha l袖 a(1) 1j = aij - ai1aij 速竪i v鱈i i 1. = = 1021 0121 0021 E 23210 21230 21211 A Giai 速o孫n 2: B鱈c a: Ly h袖ng 2 l袖m chun,nh息n h袖ng 2 v鱈i 2/3,速 nguy捉n c存c h袖ng kh存c = = 1021 03231 0021 E 23210 3110 21211 A B鱈c b: Ly h袖ng 1 tr探 速i h袖ng 2 nh息n 1/2 v袖 ly h袖ng 3 tr探 速i h袖ng 2 nh息n 1/2 = = 13131 03231 03132 E 3400 3110 3101 A Giai 速o孫n 3: B鱈c a: Ly h袖ng 3 l袖m chun,nh息n h袖ng 3 v鱈i 3/4,速 nguy捉n c存c h袖ng kh存c = = 434141 03231 03132 E 100 3110 3101 A B鱈c b: Ly h袖ng 1 tr探 速i h袖ng 3 nh息n 1/3 v袖 ly h袖ng 2 tr探 速i h袖ng 3 nh息n 1/3 = = 434141 414341 414143 E 100 010 001 A Nh vy A-1 l袖:
  • 6. 121 = 434141 414341 414143 A 1 存p d担ng ph測ng ph存p n袖y ch坦ng ta c達 ch測ng trnh sau: Ch測ng trnh 9-2 #include <conio.h>#include <stdio.h>#include <math.h>#include <stdlib.h>#include <ctype.h>void main() { int i,j,k,n,t,t1;float c,a[50][50],b[50][50]; char tl; clrscr(); printf(" **MA TRAN NGHICH DAO** n"); printf("Cho bac cua ma tran n = "); scanf("%d",&n); printf("Vao ma tran ban dau an"); for (i=1;i<=n;i++) { printf("Vao hang thu %d :n",i); for (j=1;j<=n;j++) { printf("a[%d][%d] = ",i,j); scanf("%f",&a[i][j]); } printf("n"); } printf("n"); printf("Ma tran ban da nhapn"); printf("n"); for (i=1;i<=n;i++) { for (j=1;j<=n;j++) printf("%.5ft",a[i][j]); printf("n"); } t=1; flushall(); while (t) { printf("nCo sua ma tran khong(c/k)?"); scanf("%c",&tl); if(toupper(tl)=='C') { printf("Cho chi so hang can sua : "); scanf("%d",&i); printf("Cho chi so cot can sua : "); scanf("%d",&j); printf("a[%d][%d] = ",i,j); scanf("%f",&a[i][j]); } if (toupper(tl)=='K') t=0; } printf("nMa tran ban daun");
  • 7. 122 printf("n"); for (i=1;i<=n;i++) { for (j=1;j<=n;j++) printf("%.5ft",a[i][j]); printf("n"); } printf("n"); for (i=1;i<=n;i++) for (j=n+1;j<=2*n;j++) { if (j==i+n) a[i][j]=1; else a[i][j]=0; } i=1; t1=1; while (t1&&(i<=n)) { if (a[i][i]==0) { t=1; k=i+1; while (t&&(k<=n)) if (a[k][i]!=0) { for (j=1;j<=2*n;j++) { c=a[i][j]; a[i][j]=a[k][j]; a[k][j]=c; } t=0; } else k=k+1; if (k==n+1) { if (a[i][k-1]==0) { printf("MA TRAN SUY BIENn "); t1=0; } } } if (a[i][i]!=0) { c=a[i][i]; for (j=i;j<=2*n;j++)
  • 8. 123 a[i][j]=a[i][j]/c; } for (k=1;k<=n;k++) { if (k!=i) { c=a[k][i]; for (j=i;j<=2*n;j++) a[k][j]=a[k][j]-a[i][j]*c; } } i=i+1; } if (t1) { printf("n"); printf("nMA TRAN KET QUAn"); printf("n"); for (i=1;i<=n;i++) { for (j=n+1;j<=2*n;j++) printf("%.4ftt",a[i][j]); printf("n"); } printf("n"); } getch(); } D誰ng ch測ng trnh tnh nghch 速其o c単a ma trn: 678 789 899 cho ta kt qu其 991 9102 121 則3.Tch hai ma trn Gi其 s旦 ta c達 ma trn Amn v袖 ma trn Bnp.Tch c単a Amn v袖 Bnp l袖 ma trn Cmp trong 速達 m巽i phn t旦 c単a Cmp l袖: = = n 1k kjikij bac Ch測ng trnh d鱈i 速息y th湛c hin nh息n hai ma trn v鱈i nhau. Ch測ng trnh 9-3 #include <conio.h>#include <stdio.h>#include <math.h>#include <stdlib.h>#include <ctype.h> #define max 50 void main()
  • 9. 124 { int n,l,m,i,j,k,t; float a[max][max],b[max][max],c[max][max]; char tl; clrscr(); printf("Cho so hang cua ma tran a : "); scanf("%d",&n); printf("Cho so cot cua ma tran a : "); scanf("%d",&l); printf("Cho so cot cua ma tran b : "); scanf("%d",&m); printf("nNHAP MA TRAN An"); for (i=1;i<=n;i++) for (j=1;j<=l;j++) { printf("a[%d][%d] = ",i,j); scanf("%f",&a[i][j]); } printf("n"); printf("Ma tran a ma ban da nhapn"); for (i=1;i<=n;i++) { for (j=1;j<=l;j++) printf("%10.5f",a[i][j]); printf("n"); } flushall(); t=1; while (t) { printf("Co sua ma tran khong(c/k)?"); scanf("%c",&tl); if (toupper(tl)=='C') { printf("Cho chi so hang can sua : "); scanf("%d",&i); printf("Cho chi so cot can sua : "); scanf("%d",&j); printf("a[%d][%d] = ",i,j); scanf("%f",&a[i][j]); } if (toupper(tl)=='K') t=0; } printf("Ma tran a ban dau"); printf("n"); for (i=1;i<=n;i++) { for (j=1;j<=l;j++)
  • 10. 125 printf("%10.5f",a[i][j]); printf("n"); } printf("n"); printf("NHAP MA TRAN Bn"); for (i=1;i<=l;i++) for (j=1;j<=m;j++) { printf("b[%d][%d] = ",i,j); scanf("%f",&b[i][j]); } printf("n"); printf("Ma tran b ban da nhapn"); for (i=1;i<=l;i++) { for (j=1;j<=m;j++) printf("%10.5f",b[i][j]); printf("n"); } flushall(); t=1; while (t) { printf("Co sua ma tran khong(c/k)?"); scanf("%c",&tl); if (toupper(tl)=='C') { printf("Cho chi so hang can sua : "); scanf("%d",&i); printf("Cho chi so cot can sua : "); scanf("%d",&j); printf("b[%d][%d] = ",i,j); scanf("%f",&b[i][j]); } if (toupper(tl)=='K') t=0; } printf("Ma tran b ban dau"); printf("n"); for (i=1;i<=l;i++) { for (j=1;j<=m;j++) printf("%10.5f",b[i][j]); printf("n"); } printf("n"); for (i=1;i<=n;i++) for (j=1;j<=m;j++) {
  • 11. 126 c[i][j]=0; for (k=1;k<=l;k++) c[i][j]=c[i][j]+a[i][k]*b[k][j]; } printf("Ma tran tich c :n"); for (i=1;i<=n;i++) { for (j=1;j<=m;j++) printf("%10.5f",c[i][j]); printf("n"); } getch(); } D誰ng ch測ng trnh tnh tnh hai ma trn ta nhn 速樽c kt qu其 = 1214 221 11148 105 343 221 35 01 31 12 則4.Gi存 tr ri捉ng v袖 vec t測 ri捉ng c単a ma trn 1.Kh存i nim chung: Trong nghi捉n l thuyt v袖 淡ng d担ng,ta gp b袖i to存n v ma trn cp n.Cho m辿t ma trn A cp n,gi存 tr 了 速樽c g辰i l袖 gi存 tr ri捉ng v袖 vect測 X 速樽c g辰i l袖 vect測 ri捉ng c単a ma trn A nu: AX = 了X (1) Vect測 ri捉ng ph其i l袖 vect測 kh存c kh束ng.T測ng 淡ng v鱈i m辿t gi存 tr ri捉ng c達 v束 s竪 vect測 ri捉ng.Nu X l袖 m辿t vc t測 ri捉ng t測ng 淡ng v鱈i gi存 tr ri捉ng 了 th cX c嘆ng l袖 vec t ri捉nh 淡ng v鱈i 了.C達 nhiu thut to存n tm gi存 tr ri捉ng v袖 vect測 ri捉ng c単a m辿t ma trn.Gi其 s旦 ta c達 ma trn A,g辰i E l袖 ma trn 速測n v th theo (1) ta c達: (A-了E)X = 0 (2) v袖 (A - 了E) l袖 ma trn c達 d孫ng: 了 了 了 aaa ....... aaa aaa nn2n1n n22221 n11211 .... .... .... (3) Nh vy do (2) l袖 h ph測ng trnh tuyn tnh thun nht n捉n 速iu kin cn v袖 速単 速 了 l袖 gi存 tr ri捉ng c単a ma trn tr捉n l袖 速nh th淡c c単a n達 b損ng kh束ng: det(A - 了E) = 0 (4) Ph測ng trnh (4) 速樽c g辰i l袖 ph測ng trnh 速c trng c単a ma trn A.則nh th淡c det(A - 了E) 速樽c g辰i l袖 速nh th淡c 速c trng c単a ma trn A.則nh th淡c PA(了) c単a ma trn tr捉n 速樽c g辰i l袖 速a th淡c 速c trng c単a ma trn vu束ng A. V d担 tm vec t測 ri捉ng v袖 tr ri捉ng c単a ma trn: 022 113 313 Tr鱈c ht ta tnh 速a th淡c 速c trng c単a ma trn A:
  • 12. 127 )4()4( 22 113 313 )(P 2 A + 了了= 了 了 了 =了 Nghim c単a PA(了) = 0 l袖 了1 = 4,了2 = 2j v袖 了3 = -2j.V tr棚ng c測 s谷 l袖 s竪 th湛c n捉n ta ch ly 了 = 4.則 tm vec t測 ri捉ng t測ng 淡ng v鱈i 了 = 4 ta gi其i h 0 22 113 313 3 2 1 = 両 両 両 了 了 了 ta nhn 速樽c c存c gi存 tr c単a 両,ch坦ng t孫o th袖nh vec t測 ri捉ng 淡ng v鱈i 了. Nh vy khi khai trin 速nh th淡c ta c達 m辿t 速a th淡c bc n c達 d孫ng: Pn(了) = 了n - p1了n-1 - p2了n-2 - - pn = 0 Mu竪n x存c 速nh c存c h s竪 c単a 速a th淡c 速c tnh n袖y ta d誰ng ph測ng ph存p Fadeev-Leverrier.Ta xt ma trn A: = nn2n1n n22221 n11211 aaa aaa aaa A Ta g辰i vt c単a ma trn A l袖 s竪: vet(A)= a11 + a22 +...+ ann Khi 速達 tham s竪 pi c単a Pn(了) 速樽c c存c 速nh nh sau: p1 = vet(B1) v鱈i B1 = A p2 = (1/2)vet(B2) v鱈i B2 = A(B1-p1E) p3 = (1/3)vet(B3) v鱈i B3 = A(B2-p2E) ...... Ch測ng trnh tnh c存c h s竪 pi nh sau: Ch測ng trnh 9-4 // Faddeev_Leverrier; #include <stdio.h> #include <conio.h> #include <ctype.h> #define max 50 void main() { int i,j,k,m,n,k1,t; float vet,c1,d; char tl; float p[max]; float a[max][max],b[max][max],c[max][max],b1[max][max]; clrscr(); printf("Cho bac cua ma tran n = "); scanf("%d",&n); printf("Cho cac phan tu cua ma tran a : n");
  • 13. 128 for (i=1;i<=n;i++) for (j=1;j<=n;j++) { printf("a[%d][%d] = ",i,j ); scanf("%f",&a[i][j]); } printf("n"); clrscr(); printf("Ma tran ban da nhap"); printf("n"); for (i=1;i<=n;i++) { for (j=1;j<=n;j++) printf("%10.5f",a[i][j]); printf("n"); } t=1; flushall(); while (t) { printf("n"); printf("Co sua ma tran khong(c/k)?"); scanf("%c",&tl); if (toupper(tl)=='C') { printf("Cho chi so hang can sua : "); scanf("%d",&i); printf("Cho chi so cot can sua : "); scanf("%d",&j); printf("a[%d][%d] = ",i,j); scanf("%f",&a[i][j]); flushall(); } if (toupper(tl)=='K') t=0; } printf("Ma tran ban dau"); printf("n"); for (i=1;i<=n;i++) { for (j=1;j<=n;j++) printf("%10.5f",a[i][j]); printf("n"); } for (i=1;i<=n;i++) for (j=1;j<=n;j++) b[i][j]=a[i][j]; for (k=1;k<=n-1;k++) { vet=0.0;
  • 14. 129 for (i=1;i<=n;i++) vet+=b[i][i]; p[k]=vet/k; for (i=1;i<=n;i++) for (j=1;j<=n;j++) { if (j!=i) c[i][j]=b[i][j]; if (j==i) c[i][j]=b[i][j]-p[k]; } for (i=1;i<=n;i++) for (j=1;j<=n;j++) { b[i][j]=0.0; for (k1=1;k1<=n;k1++) b[i][j]+=a[i][k1]*c[k1][j]; } } vet=0.0; for (i=1;i<=n;i++) vet+=b[i][i]; p[n]=vet/n; printf("n"); printf("Cac he so cua da thuc dac trungn"); printf("n"); d=1.0; printf("%6.2f",d); for (i=1;i<=n;i++) { c1=-p[i]; printf("%5c%6.2f",' ',c1); } getch(); } 2.Ph測ng ph存p Mises: Thut to存n Mises tm gi存 tr ri捉ng l鱈n nht c単a m辿t ma trn A. Nu ma trn A l袖 th湛c v袖 v袖 m巽i tr ri捉ng b辿i k c達 速単 k vec t測 ri捉ng 速辿c lp tuyn tnh th vic tnh to存n s cho ta gi存 tr ri捉ng l鱈n nht. M辿t vect測 V bt k c達 th 速樽c vit d鱈i d孫ng: = =+++= n 1i iinn2211 XvXvXvXvV (5) Trong 速達 X1,X2,..,Xn l袖 c存c vec t測 ri捉ng t測ng 淡ng v鱈i c存c gi存 tr ri捉ng 了1,了2,了3,..,了n v袖 v1,v2,v3,...,vn l袖 c存c h損ng s竪. Khi nh息n A v鱈i V ta c達: AV = Av1X1 + Av2X2 +....+ AvnXn do: Av1X1 = v1AX1 = v1了1X1 ; Av2X2 = v2AX2 = v2了2X2 v.v. Vy n捉n: AV = v1了1X1 + v2了2X2 +...+ vn了nXn
  • 15. 130 XvXAvAV ii n 1i iii n 1i i 了 == == L孫i nh息n biu th淡c tr捉n v鱈i A ta c達: A2 V = v1了1 AX1 + v2了2 AX2 +...+ vn了n AXn = v1了2 1X1 + v2了2 2 X2 +...+ vn了n 2 Xn v袖 tip 速n ln th淡 p ta c達: XvXvXvXvVA n p nn2 p 211 p 11i p i n 1i i p 了了了了 +++== = Ly 了p 1 l袖m th探a s竪 chung ta c達: ・ ・ ヲ 、 「 「 」 。 了 了 ++ 了 了 + 了 了 +了= n p 1 n n3 p 1 3 32 p 1 2 211 p 1 p XvXvXvXvVA T測ng t湛 ta c達: ・ ・ ヲ 、 「 「 」 。 了 了 ++ 了 了 + 了 了 +了= +++ ++ n 1p 1 n n3 1p 1 3 32 1p 1 2 211 1p 1 1p XvXvXvXvVA Khi p rt l鱈n,v 了1 > 了2 > 了3 >,...,了n n捉n: 了 了 pkhi0 1 i Do 速達: 11 p 1 p p XvVAlim 了= (6) 11 1p 1 1p p XvVAlim ++ 了= ngha l袖 khi p 速単 l鱈n th: 11 p 1 p XvVA 了= 11 1p 1 1p XvVA ++ 了= do 速達: VAVA p 1 1p 了=+ hay: ( ) VAVAA p 1 p 了= Nh vy VAp l袖 vc t測 ri捉ng c単a A 淡ng v鱈i 了1 cn gi存 tr ri捉ng 了1 s l袖: 1p 1p p VA VA lim 了= + Trong th湛c t 速 tr存nh v樽t qu存 dung l樽ng b辿 nh鱈 khi 了1 kh存 l鱈n,c存c vect測 Vk 速樽c chun ho存 sau m巽i b鱈c b損ng c存ch chia c存c phn t旦 c単a n達 cho phn t旦 l鱈n nht mk v袖 nhn 速樽c vect測 V k Nh vy c存c b鱈c tnh s l袖: - cho m辿t vec t測 V bt k (c達 th l袖 V = { 1,1,1,...,1}T ) - tnh V1 = AV v袖 nhn 速樽c phn t旦 l鱈n nht l袖 m1j t探 速達 tnh tip V 1 = V1/m1j M辿t c存ch t脱ng qu存t,t孫i ln lp th淡 p ta nhn 速樽c vect測 Vp v袖 phn t旦 l鱈n nht mpj th V p = Vp/ mpj. - tnh p1p VAV =+ v鱈i vp+1,j l袖 phn t旦 th淡 j c単a Vp+1.Ta c達: ェゥ ェ ィ ァ 了= = + 1j,1p p 1p p vlim XVlim V d担: Tm gi存 tr ri捉ng l鱈n nht v袖 vec t測 ri捉ng t測ng 淡ng c単a ma trn:
  • 16. 131 = 26544323 68102 720138 17302417 A Ch辰n V= {1,1,1,1}T ta tnh 速樽c V V1 = AV V1 V2 = AV1 V2 1 88 -0.6027 -6.4801 -0.5578 1 48 -0.3288 -5.6580 -0.4870 1 26 -0.1781 0.0818 0.0070 1 -146 1 11.6179 1 了 11.6179 V3 = AV2 V3 V4 = AV3 V4 V5 = AV4 -3.9594 -0.5358 -3.6823 -0.5218 -3.5718 -3.6526 -0.4942 -3.5196 -0.4987 -3.4791 0.0707 0.0096 0.0630 0.0089 0.0408 7.3902 1 7.0573 1 6.9638 了 7.3902 7.0573 6.9638 V5 V6= AV5 V6 V7= AV6 V7 - 0.5129 -3.5341 -0.5075 -3.5173 -0.5043 - 0.4996 -3.4809 -0.4999 -3.4868 -0.5000 0.0059 0.0250 0.0036 0.0147 0.0021 1 6.9634 1 6.9742 1 了 6.9634 6.9742 D誰ng thut to存n tr捉n ta c達 ch測ng trnh sau: Ch測ng trnh 9-5 #include <conio.h>#include <stdio.h>#include <math.h>#include <stdlib.h>#include <ctype.h>#define max 50void main() { int i,j,k,n,t; char tl; float t0,t1,epsi,s; float a[max][max]; float x0[max],x1[max]; clrscr(); printf("Phuong phap lap luy thua tim tri rieng lon nhatn"); printf("Cho so hang va cot cua ma tran n = "); scanf("%d",&n); printf("Cho cac phan tu cua ma tran a : n"); for (i=1;i<=n;i++) for (j=1;j<=n;j++)
  • 17. 132 { printf("a[%d][%d] = ",i,j); scanf("%f",&a[i][j]); } printf("n"); printf("Ma tran ban da nhapn"); printf("n"); for (i=1;i<=n;i++) { for (j=1;j<=n;j++) printf("%15.5f",a[i][j]); printf("n"); } flushall(); t=1; while (t) { printf("nCo sua ma tran khong(c/k)?"); scanf("%c",&tl); if (toupper(tl)=='C') { printf("Cho chi so hang can sua : "); scanf("%d",&i); printf("Cho chi so cot can sua : "); scanf("%d",&j); printf("a[%d][%d] = ",i,j); scanf("%f",&a[i][j]); } if (toupper(tl)=='K') t=0; } epsi=1e-5; printf("nMa tran ban daun"); printf("n"); for (i=1;i<=n;i++) { for (j=1;j<=n;j++) printf("%15.5f",a[i][j]); printf("n"); } printf("n"); for (i=1;i<=n;i++) x0[i]=1; k=1; t=0; t1=0; do { t0=t1; for (i=1;i<=n;i++)
  • 18. 133 { x1[i]=0; for (j=1;j<=n;j++) x1[i]=x1[i]+a[i][j]*x0[j]; } s=0; j=0; for (i=1;i<=n;i++) if (s<fabs(x1[i])) { j=i; s=fabs(x1[i]); } t1=x1[j]; for (i=1;i<=n;i++) x1[i]=x1[i]/t1; if (fabs(t1-t0)<epsi) { printf("Da thuc hien %d buoc lapn",k); printf("Gia tri rieng lon nhat Vmax = %15.5fn",t1); printf("Vec to rieng tuong ungn"); for (i=1;i<=n;i++) printf("%.5fn",x1[i]); t=1; } if (fabs(t1-t0)>epsi) { for (i=1;i<=n;i++) x0[i]=x1[i]; k=k+1; } if (k>max) t=1; } while(t==0); getch(); } D誰ng ch測ng trnh n袖y tnh ga tr ri捉ng v袖 vec t測 ri捉ng c単a ma trn: 308 649 012 ta nhn 速樽c gi存 tr ri捉ng l袖 3.0000 v袖 vec t測 ri捉ng l袖 x = { -0.75 ; 0.75 ; 1 }T Nh ch坦ng ta 速揃 n達i tr鱈c 速息y,ph測ng ph存p Mises (hay cn g辰i l袖 ph測ng ph存p lp l嘆y th探a) ch cho php tm gi存 tr ri捉ng l鱈n nht v袖 vec t測 ri捉ng t測ng 淡ng c単a ma trn.則 x存c 速nh c存c gi存 tr ri捉ng kh存c,ma trn A 速樽c bin 速脱i th袖nh m辿t ma trn kh存c A1 m袖 c存c gi存 tr ri捉ng l袖 了2 > 了3 >...> 了n.Ph測ng ph存p n袖y g辰i l袖 ph測ng ph存p xu竪ng thang.Sau 速息y l袖 ph測ng ph存p bin 速脱i ma trn:
  • 19. 134 Gi其 s旦 X1 l袖 vec t測 ri捉ng c単a ma trn A t測ng 淡ng v鱈i gi存 tr ri捉ng 了1 v袖 W1 l袖 vec t測 ri捉ng c単a ma trn AT t測ng 淡ng v鱈i gi存 tr ri捉ng 了1.T探 速nh ngha AX1 = 了1X1 ta vit: (A - 了E)X1 = 0 Ta t孫o ma trn A1 d孫ng: WX XW AA T 11 1 T 1 1 1 了= (7) Ta ch坦 箪 l袖 X1W1 T l袖 m辿t ma trn cn W1 T X1 l袖 m辿t con s竪.Khi nh息n hai v c単a biu th淡c (7) v鱈i X1 v袖 ch箪 箪 速n tnh kt h樽p c単a tch c存c ma trn ta c達: 0 XAX XW XW XAX XWX XW AXXA 111 1 T 1 1 T 1 111 1 T 11 1 T 1 1 111 = = = = 了 了 了 (8) A1 chp nhn gi存 tr ri捉ng b損ng kh束ng. Nu X2 l袖 vec t測 ri捉ng t測ng 淡ng v鱈i gi存 tr ri捉ng 了2,th khi nh息n A1 v鱈i X2 ta c達: XW XW XAX XWX XW AXXA 1 T 1 2 T 1 112 2 T 11 1 T 1 1 221 了 了 = = (9) Theo 速nh ngha v W1 l袖 vect測 ri捉ng c単a AT n捉n: 了1W1 =AT W1 (10) Mt kh存c do: (AX)T =XT AT v袖 (AT )T = A N捉n khi chuyn v (10) ta nhn 速樽c: (AT W1)T = 了1WT 1 Hay: W1 T A = 了1W1 T (11) Khi nh息n (11) v鱈i X2 ta c達: 了1W1 T X2 = W1 T AX2 v袖 do 速nh ngha: AX2 = 了2X2 n捉n: 了1W1 T X2 = W1 T 了2X2 vy th: (了1 - 了2) W1 T X2 = 0 khi 了1 了2 th: W1 T X2 = 0 (12) Cu竪i c誰ng thay (12) v袖o (9) ta c達: A1X2 = AX2 = 了2X2 Nh vy 了2 l袖 gi存 tr ri捉ng l鱈n nht c単a ma trn A1 v袖 nh vy c達 th 存p d担ng thut to存n n袖y 速 tm c存c gi存 tr ri捉ng cn l孫i c単a ma trn.C存c b鱈c tnh to存n nh sau - khi 速揃 c達 了1 v袖 X1 ta tm W1 l袖 vec t測 ri捉ng c単a AT 淡ng v鱈i gi存 tr ri捉ng 了1 (v d担 tm W1 b損ng c存ch gi其i ph測ng trnh (AT -了1E)W1 = 0).T探 速達 tnh ma trn A12 theo (7). - tm gi存 tr ri捉ng v袖 vec t測 ri捉ng c単a A1 b損ng c存ch lp c束ng sut v袖 c淡 th tip t担c v袖 xu竪ng thang (n-1) ln ta tm 速単 n gi存 tr ri捉ng c単a ma trn A. V d担: Tm gi存 tr ri捉ng v袖 vect測 ri捉ng c単a ma trn sau:
  • 20. 135 = 26544323 68102 720138 17302417 A Ta 速揃 tm 速樽c gi存 tr ri捉ng l鱈n nht 了1 = 7 v袖 m辿t vect測 ri捉ng t測ng 淡ng: X1 = { 1,1,0,-2}T . Ma trn AT c達 d孫ng: = 266717 5482030 43101324 232817 A T v袖 theo ph測ng trnh AT -了1E)W1 = 0 ta tm 速樽c vect測 W1 = {293,695,746,434}T Ta lp ma trn m鱈i A1 theo (7): =了 86814921390586 0000 434746695293 434746695293 120 7 XW WX 1 T 1 T 11 1 v袖: = 6333.240333.330833.381833.11 68102 3167.185167.235417.270917.9 3167.85167.135417.160917.0 A1 T探 ma trn A1 ta tm tip 速樽c 了2 theo php lp lu端 th探a v袖 sau 速達 l孫i tm ma trn A3 v袖 tm gi存 tr ri捉ng t測ng 淡ng. Ch測ng trnh lp tm c存c gi存 tr ri捉ng v袖 vec t測 ri捉ng c単a ma trn nh sau: Ch測ng trnh 9-6 #include <conio.h> #include <stdio.h> #include <math.h> #include <stdlib.h> #include <ctype.h> #define max 50 void main() { float a[max][max],vv[max][max],at[max][max]; float x[max],y[max],vd[max]; int i,j,k,n,l,t; float vp,v1,z,epsi,va,ps; char tl; clrscr(); epsi=0.000001; printf("Cho bac cua ma tran n = "); scanf("%d",&n); printf("Cho cac phan tu cua ma tran a : n"); for (i=1;i<=n;i++) for (j=1;j<=n;j++)
  • 21. 136 { printf("a[%d][%d] = ",i,j); scanf("%f",&a[i][j]); } printf("n"); clrscr(); printf("Ma tran ban da nhap"); printf("n"); for (i=1;i<=n;i++) { for (j=1;j<=n;j++) printf("%15.5f",a[i][j]); printf("n"); } t=1; flushall(); while (t) { printf("n"); printf("Co sua ma tran khong(c/k)?"); scanf("%c",&tl); if (toupper(tl)=='C') { printf("Cho chi so hang can sua : "); scanf("%d",&i); printf("Cho chi so cot can sua : "); scanf("%d",&j); printf("a[%d][%d] = ",i,j); scanf("%f",&a[i][j]); } if (toupper(tl)=='K') t=0; } for (l=1;l<=n;l++) { for (i=1;i<=n;i++) x[i]=1; vp=1.23456789; k=0; for (k=1;k<=40;k++) { for (i=1;i<=n;i++) { y[i]=0; for (j=1;j<=n;j++) y[i]=y[i]+a[i][j]*x[j]; } v1=y[1]/x[1]; z=0; for (i=1;i<=n;i++)
  • 22. 137 if (fabs(y[i])>z) z=y[i]; for (i=1;i<=n;i++) x[i]=y[i]/z; if (fabs(vp-v1)<epsi) break; vp=v1; } { printf("Gia tri rieng : %9.6fn",v1); printf("Vec to rieng : n"); for (i=1;i<=n;i++) printf("%.5fn",x[i]); printf("n"); getch(); } vd[l]=v1; va=v1; for (i=1;i<=n;i++) vv[l][i]=x[i]; for (i=1;i<=n;i++) for (j=1;j<=n;j++) at[i][j]=a[j][i]; for (i=1;i<=n;i++) x[i]=1; vp=1.23456; k=0; for (k=1;k<=40;k++) { for (i=1;i<=n;i++) { y[i]=0; for (j=1;j<=n;j++) y[i]=y[i]+at[i][j]*x[j]; } v1=y[1]/x[1]; z=0; for (i=1;i<=n;i++) if (fabs(y[i])>z) z=y[i]; for (i=1;i<=n;i++) x[i]=y[i]/z; if (fabs(vp-v1)<epsi) break; vp=v1; } if (fabs(vp-v1)>epsi) { printf("Khong hoi tu sau 40 lan lapn"); getch();
  • 23. 138 exit(1); } if (fabs(va-v1)>3*epsi) { printf("Co loin"); getch(); exit(1); } ps=0; for (i=1;i<=n;i++) ps=ps+x[i]*vv[l][i]; ps=v1/ps; for (i=1;i<=n;i++) for (j=1;j<=n;j++) a[i][j]=a[i][j]-ps*vv[l][i]*x[j]; } }
  • 24. 139 Do (6) 速坦ng v鱈i m辰i n n捉n cho n = 1 , 2 , 3 , . . . ta c達 : | x2 - x1 | q | x1 - xo | | x3 - x2 | q | x2 - x1 | . . . . . . . . . . . . . . . . . . . | xn+1 - xn | q | xn - xn-1 | 則iu n袖y c達 ngha l袖 d揃y xi+1 - xi , m辿t c存ch gn 速坦ng,l袖 m辿t cp s竪 nh息n . Ta c嘆ng coi r損ng d揃y xn - y v鱈i y l袖 nghim 速坦ng c単a (1) , gn 速坦ng nh- m辿t cp s竪 nh息n c達 c束ng sai q . Nh- vy : 1q yx yx n 1n <= + (7) hay : )yx(qyx n1n =+ (8) T-測ng t湛 ta c達 : )yx(qyx 1n2n = ++ (9) T探 (8) v袖 (9) ta c達 : n1n 1n2n xx xx q = + ++ (10) Thay gi存 tr c単a q v探a tnh 谷 (10) v袖o biu th淡c c単a q 谷 tr捉n ta c達 : ( ) 1n1nn 2 1nn n xx2x xx xy ++ + + = (11) C束ng th淡c (11) 速-樽c g辰i l袖 c束ng th淡c ngo孫i suy Adam.Nh- vy theo (11) tr-鱈c ht ta d誰ng ph-測ng ph存p lp 速 tnh gi存 tr gn 速坦ng xn+2,xn+1,xn c単a nghim v袖 sau 速達 theo (11) tm 速-樽c nghim v鱈i sai s竪 nh叩 h測n. 則 l袖m v d担 ch坦ng ta xt ph-測ng trnh : lnx - x2 + 3 = 0 Ta 速-a v d孫ng lp : 3)xln(x += 3xlnx2 1 )x(f + = Php lp h辿i t担 trong 速o孫n [0.3,].Ta cho x1 = 1 th tnh 速-樽c : x2 = 1,7320508076 x3 = 1.883960229 x4 = 1.90614167 y = 1.909934347 則 gi其m sai s竪 ta c達 th lp nhiu ln Ch測ng trnh 8-9 //phuong phap Aitken #include <conio.h> #include <stdio.h> #include <math.h> #define m 5 void main() {
  • 25. 140 float x[m]; float epsi,n,y; int i,z; float f(float); clrscr(); printf("Cho tri so ban dau x[1] = "); scanf("%f",&x[1]); printf("Cho tri so sai so epsilon = "); scanf("%f",&epsi); printf("n"); printf( "Ngoai suy Aitken cua hamn"); z=0; while (z<=20) { for (i=2;i<=4;i++) x[i]=f(x[i-1]); n=x[4]-2*x[3]+x[2]; if ((fabs(n)<1e-09)||(fabs(x[1]-x[2])<epsi*fabs(x[1]))) z=20; else { y=x[2]-(x[3]-x[2])*(x[3]-x[2])/n; if (z>20) printf("Khong hoi tu sau hai muoi lan lapn"); x[1]=y; } z=z+1; } printf("Nghiem cua phuong trinh y = %.6f",y); getch(); } float f(float x) { float s=sqrt(log(x)+3); return(s); } V鱈i gi存 tr ban 速u l袖 1 v袖 sai s竪 l袖 1e-8,ch-測ng trnh cho kt qu其 y = 1.9096975944 則10.Ph測ng ph存p Bairstow Nguy捉n t他c c単a ph-測ng ph存p Bairstow l袖 trch t探 速a th淡c Pn(x) m辿t tam th淡c Q2(x) = x2 - sx + p m袖 ta c達 th tnh nghim th湛c hay nghim ph淡c c単a n達 m辿t c存ch 速測n gi其n b損ng c存c ph-測ng ph存p 速揃 bit. Vic chia 速a th淡c Pn(x) cho tam th淡c Q2(x) 速-a t鱈i kt qu其 : Pn(x) = Q2(x).Pn-2(x) + R1(x) v鱈i Pn(x) = aoxn + a1xn-1 + a2xn-2 +...+ an
  • 26. 141 Q2(x) = x2 - sx + p Pn-2(x) = boxn-2 + b1xn-3 + b2xn-4 +...+ bn-2 R1(x) = 留x + 硫 則 c達 速-樽c m辿t th-測ng 速坦ng,cn tm c存c gi存 tr c単a s v袖 p sao cho R1(x) = 0 (ngha l袖 留 v袖 硫 trit ti捉u).V鱈i s v袖 p 速揃 cho,c存c h s竪 b c単a 速a th淡c Pn-2(x) v袖 c存c h s竪 留 v袖 硫 速-樽c tnh b損ng ph-測ng ph存p truy h奪i.C存c c束ng th淡c nhn 速-樽c khi khai trin biu th淡c Pn(x) = Q2(x).Pn-2(x) + R1(x) v袖 s他p xp l孫i c存c s竪 h孫ng c誰ng bc : aoxn + a1xn-1 + a2xn-2 +...+ an = (x2 - sx + p)( boxn-2 + b1xn-3 + b2xn-4 +...+ bn-2) S竪 h孫ng bc H s竪 c単a Pn(x) H s竪 c単a Q2(x).Pn-2(x) xn ao bo xn-1 a1 b1 - sbo xn-2 a2 b2 - sb1 + pbo ...... ...... ..... xn-k ak bk - sbk-1 + pbk-2 x an-1 留 - sbn-2 + pbn-3 xo an 硫 + pbn-2 Nh- vy : bo = a o (1) b1 = a1 + sbo b2 = a2 + sb1 - pbo .................. bk = ak + sbk-1 - pbk-2 留 = an-1 + sbn-2 - pbn-3 硫 = an - pbn-2 Ch坦ng ta nhn thy r損ng 留 速-樽c tnh to存n xut ph存t t探 c誰ng m辿t c束ng th淡c truy h奪i nh- c存c h s竪 bk v袖 t-測ng 淡ng v鱈i h s竪 bn-1 bn-1 = an-1 + sbn-2 - pbn-3 = 留 H s竪 bn l袖 : bn = an + sbn-1 - pbn-2 = sbn-1 + 硫 v袖 cu竪i c誰ng : R1(x) = 留x + 硫 = bn-1(x - s) + bn Ngo袖i ra c存c h s竪 bi ph担 thu辿c v袖o s v袖 p v袖 b息y gi棚 ch坦ng ta cn ph其i tm c存c gi存 tr 速c bit s* v袖 p* 速 cho bn-1 v袖 bn trit ti捉u.Khi 速達 r1(x) = 0 v袖 nghim c単a tam th淡c x2 - s* x + p* x s l袖 nghim c単a 速a th淡c Pn(x).Ta bit r損ng bn-1 v袖 bn l袖 h袖m c単a s v袖 p : bn-1 = f(s,p) bn = g(s,p) Vic tm s* v袖 p* 速-a 速n vic gi其i h ph-測ng trnh phi tuyn: ゥ ィ ァ = = 0)p,s(g 0)p,s(f Ph-測ng trnh n袖y c達 th gi其i d d袖ng nh棚 ph-測ng ph存p Newton.Tht vy v鱈i m辿t ph-測ng trnh phi tuyn ta c達 c束ng th淡c lp : xi+1 = xi - f(xi)/f'(xi) hay f'(xi)(xi+1 - xi) = -f(xi) V鱈i m辿t h c達 hai ph-測ng trnh,c束ng th淡c lp tr谷 th袖nh:
  • 27. 142 J(Xi)(Xi+1 - Xi) = -F(Xi) v鱈i Xi = { si,pi}T v袖 Xi+1 = { si+1,pi+1}T )p,s(g )p,s(f )X(F ii ii i = i J X f s f p g s g p ( )= Quan h : J(Xi)X = -F(Xi) v鱈i X = {si+1 - si,pi+1 - pi}T t-測ng 淡ng v鱈i m辿t h ph-測ng trnh tuyn tnh hai n s竪 s = si+1 - si v袖 p = pi+1 - pi : f s s f p p f s p g s s g p p g s p i i i i + = + = ァ ィ ェ ェ ェ ゥ ェ ェ ェ ( ) ( ) , , Theo c束ng th淡c Cramer ta c達 : s f g p g f p = + 隆 p g f s f g s= + 隆 隆 = f s g p f p g s 則 d誰ng 速-樽c c束ng th淡c n袖y ta cn tnh 速-樽c c存c 速孫o h袖m f s , f p , g s , g p .C存c 速孫o h袖m n袖y 速-樽c tnh theo c束ng th淡c truy h奪i. Do bo = ao n捉n ob s =0 ob p =0 b1 = a1 + sbo n捉n 1 b s bo = 1 0 b p = b2 = a2 + sb1- pbo n捉n 2 2 1 b s a s sb s pb s o = + ( ) ( ) Mt kh存c : 2 0 a s = 1 1 1 ( )sb s s b s b= + o pb s ( ) =0 n捉n : 2 1 b s b sbo = + b3 = a3 + sb2- pb1 n捉n 3 2 2 1 b s b s b s p b s = + Nu ch坦ng ta 速t : k k b s c = 1
  • 28. 143 th : co = bo (2) c1 = b1 + sbo = b1 + sco c2 = b2 + sc1 - pco .................... ck = bk + sck-1 - pck-2 cn-1 = bn-1 + scn-2 - pcn-3 Nh- vy c存c h s竪 c嘆ng 速-樽c tnh theo c存ch nh- c存c h s竪 bk.Cu竪i c誰ng v鱈i f = bn-1 v袖 g = bn ta 速-樽c: 2n1n3n2n c s f c s f c s f c s f = = = = 2 2n3n1n 3nn2n1n ccc cbcb s = (3) 2 2n3n1n 2nn1n1n ccc cbcb p = (4) Sau khi ph息n tch xong Pn(x) ta tip t担c ph息n tch Pn-2(x) theo ph-測ng ph存p tr捉n C存c b-鱈c tnh to存n g奪m : - Ch辰n c存c gi存 tr ban 速u bt k s0 v袖 p0 - Tnh c存c gi存 tr bo,..,bn theo (1) - Tnh c存c gi存 tr co,...,cn theo (2) - Tnh so v袖 po theo (3) v袖 (4) - Tnh s1 = s0 + so v袖 p1 = po+ po - Lp l孫i b-鱈c 1 cho 速n khi pi+1 = pi = p v袖 si+1 = si = s - Gi其i ph-測ng trnh x2 - sx + p 速 tm 2 nghim c単a 速a th淡c - B他t 速u qu存 trnh tr捉n cho 速a th淡c Pn-2(x) V d担 : Tm nghim c単a 速a th淡c P4(x) = x4 - 1.1x3 + 2.3x2 + 0.5x2 + 3.3. V鱈i ln lp ban 速u ta ch辰n s = -1 v袖 p =1,ngha l袖 tam th淡c c達 d孫ng x2 + x + 1 a0 a1 a2 a3 a4 1 -1.1 2.3 0.5 3.3 sbi -1 2.1 -3.4 0.8 -pbi-1 -1 2.1 -3.4 bi 1 -2.1 3.4 -0.8 = bn-1 0.7=bn sbi -1.0 3.1 -5.5 -pbi-1 -1.0 3.1 ci 1 -3.1 5.5 -3.2 11.0 5.52.3 1.35.5 5.57.0 1.38.0 s = = 06.0 5.52.3 1.35.5 7.02.3 8.05.5 p = =
  • 29. 144 s* = -1 + 0.11 = -0.89 p* = 1 + 0.06 = 1.06 Tip t担c lp ln 2 v鱈i s1 = s* v袖 p1 = p* ta c達 : a0 a1 a2 a3 a4 1 -1.1 2.3 0.5 3.3 sbi -0.89 1.77 -2.68 0.06 -pbi-1 -1.06 2.11 -3.17 bi 1 -1.99 3.01 -0.07 = bn-1 0.17=bn sbi -0.89 2.56 -4.01 -pbi-1 -1.0 3.1 ci 1 -2.88 4.51 -1.03 01.0 51.403.1 88.251.4 5.57.0 88.207.0 s = = 04.0 51.403.1 88.251.4 17.003.1 07.051.4 p = = s* = -0.89 - 0.01 = -0.9 p* = 1.06 + 0.04 = 1.1 Nh- vy P4(x) = (x2 +0.9x+1.1)(x2 + 2x+3) Ch-測ng trnh sau 存p d担ng l thuyt v探a n捉u 速 tm nghim c単a 速a th淡c. Ch測ng trnh 8-10 //phuong phap Bairstow #include <conio.h> #include <stdio.h> #include <math.h> #include <stdlib.h> #define m 10 void main() { float a[m],b[m],c[m]; int i,n,v; float s,e1,t,p,q,r,p1,q1; clrscr(); printf("Cho bac cua da thuc n = "); scanf("%d",&n); printf("Cho cac he so cua da thuc can tim nghiemn"); for (i=n;i>=0;i--) {
  • 30. 145 printf("a[%d] = ",n-i); scanf("%f",&a[i]); } printf("n"); e1=0.0001; if (n<=2) if (n==1) { printf("Nghiem cua hen"); printf("%.8f",(a[0]/(-a[1]))); getch(); exit(1); } do { v=0; p=1; q=-1; b[n]=a[n]; c[n]=a[n]; do { b[n-1]=b[n]*p+a[n-1]; c[n-1]=b[n-1]+b[n]*p; for (i=n-2;i>=0;i--) { b[i]=b[i+2]*q+b[i+1]*p+a[i]; c[i]=c[i+2]*q+c[i+1]*p+b[i]; } r=c[2]*c[2]-c[1]*c[3]; p1=p-(b[1]*c[2]-b[0]*c[3])/r; q1=q-(b[0]*c[2]-b[1]*c[1])/r; if ((fabs(b[0])<e1)&&(fabs(b[1])<e1)) goto tt; v=v+1; p=p1; q=q1; } while (v<=40); if(v>40) { printf("Khong hoi tu sau 40 lan lap"); getch(); exit(1); } tt:s=p1/2; t=p1*p1+4*q1; if(t<0) { printf("Nghiem phucn");
  • 31. 146 printf("%.8f+%.8fjn",s,(sqrt(-t)/2)); printf("%.8f-%.8fjn",s,(sqrt(-t)/2)); printf("n"); } else { printf("Nghiem thucn"); printf("%.8fn",(s+sqrt(t)/2)); printf("%.8fn",(s-sqrt(t)/2)); printf("n"); } for (i=2;i<=n;i++) a[i-2]=b[i]; n=n-2; } while ((n>2)&(r!=0.0)); s=-a[1]/(2*a[2]); t=a[1]*a[1]-4*a[2]*a[0]; if (t<0) { printf("Nghiem phucn"); printf("%.8f+%.8fjn",s,(sqrt(-t)/(2*a[2]))); printf("%.8f-%.8fjn",s,(sqrt(-t)/(2*a[2]))); printf("n"); } else { printf("Nghiem thucn"); printf("%.8fn",(s-sqrt(t)/(2*a[2]))); printf("%.8fn",(s-sqrt(t)/(2*a[2]))); printf("n"); } getch(); } D誰ng ch-測ng trnh tr捉n 速 x存c 速nh nghim c単a 速a th淡c : x6 - 2x5 - 4x4 + 13x3 - 24x2 + 18x - 4 = 0 ta nhn 速-樽c c存c nghim : x1 = 2.61903399 x2 = -2.73205081 x3 = 0.732050755 x4 = 0.381966055 x5 = 0.500011056 + i*1.3228881 x6 = 0.500011056 - i*1.3228881 則11.H ph測ng trnh phi tuyn Ph-測ng ph存p Newton c達 th 速-樽c t脱ng qu存t ho存 速 gi其i h ph-測ng trnh phi tuyn d孫ng :
  • 32. 147 ェ ェ ェ ゥ ェ ェ ェ ィ ァ = = = = 0)x,...,x,x,x(f ............................... 0)x,...,x,x,x(f 0)x,...,x,x,x(f 0)x,...,x,x,x(f 2321n 23213 23212 23211 hay vit g辰n h測n d-鱈i d孫ng : F(X) = 0 Trong 速達 : X = (x1,x2,x3,.....,xn) V鱈i m辿t ph-測ng trnh m辿t bin,c束ng th淡c Newton l袖 : i i i i x x f x f x+ = 1 ( ) '( ) hay : f'(xi).x = -f(xi) v鱈i x = xi+1 - xi 則竪i v鱈i h,c束ng th淡c lp l袖 : J(Xi)x = -F(Xi) Trong 速達 J(Xi) l袖 to存n t旦 Jacobi.N達 l袖 m辿t ma trn bc n ( n - t-測ng 淡ng v鱈i s竪 th袖nh phn trong vect測 X) c達 d孫ng : i n n n n n n n J x f x f x f x f x f x f x f x f x f x f x f x f x ( ) . . .............. .............. .............. = 1 1 1 2 1 3 1 2 1 2 2 2 3 2 1 2 3 v袖 X = Xi+1 - Xi Ph-測ng ph存p Newton tuyn tnh ho存 h v袖 nh- vy v鱈i m巽i b-鱈c lp cn gi其i m辿t h ph-測ng trnh tuyn tnh (m袖 bin l袖 xi) x存c 速nh b谷i c束ng th淡c lp cho t鱈i khi vect測 X(x1,x2,x3,.....,xn) gn v鱈i nghim. D-鱈i 速息y l袖 ch-測ng trnh gi其i h ph-測ng trnh phi tuyn 1 3 2 3 1 2 4 1 2 3 4 1 2 3 1 2 3 4 3 8 0 5 0 25 8 4 0 2 8 0 x x x x x x x x x x x x x x x = + + + = + + = + = ァ ィ ェ ェ ェ ゥ ェ ェ ェ Ma trn 速孫o h袖m ri捉ng J(xi)l袖 : 1 2 2 4 2 2 1 4 1 2 1 2 3 2 3 2 3 3 3 3 3 0 3 1 1 1 1 25 0 8 0 2 2 2 1 1 2 x x x x x x x x x x x x x x x x Ma trn n袖y 速-樽c ch-測ng trnh 速辰c v袖o nh棚 th単 t担c doc.Trong th単 t担c n袖y,c存c h s竪 a[i,5] l袖 c存c h袖m fi(x).Vect測 nghim ban 速u 速-樽c ch辰n l袖 { 0,-1,-1,1}T .Kt qu其 tnh cho ta : x = {0.01328676,-1.94647929,-1.12499779,8.05819031 }T v鱈i 速辿 chnh x存c 0.000001.Vect測 s竪 d- r = { 0.00000536,-0.00000011,-0.00000001,-0.00000006}T .
  • 33. 148 Ch測ng trnh 8-11 //giai he pt phi tuyen #include <conio.h> #include <stdio.h> #include <math.h> #include <stdlib.h> #define n 4 float a[n+1][n+2]; float x[n+1],y[n+1]; int i,j,k,l,z,r; float e,s,t; void main() { void doc(); clrscr(); printf("Cho cac gia tri nghiem ban daun"); for (i=1;i<=n;i++) { printf("x[%d] = ",i); scanf("%f",&x[i]); } e=1e-6; z=30; for (r=1;r<=z;r++) { doc(); for (k=1;k<=n-1;k++) { s=0 ; for (i=k;i<=n;i++) { t=fabs(a[i][k]); if (s<=t) { s=t; l=i; } } for (j=k;j<=n+1;j++) { s=a[k][j]; a[k][j]=a[l][j]; a[l][j]=s; } if (a[1][1]==0) {
  • 34. 149 printf("Cac phan tu duong cheo cua ma tran bang khong"); getch(); exit(1); } else { if (fabs(a[k][k]/a[1][1])<(1e-08)) { printf("Ma tran suy bien"); goto mot; } } for (i=k+1;i<=n;i++) { if (a[k][k]==0) { printf("Cac phan tu duong cheo cua ma tran bang khongn"); goto mot; } s=a[i][k]/a[k][k]; a[i][k]=0; for (j=k+1;j<=n+1;j++) a[i][j]=a[i][j]-s*a[k][j]; } y[n]=a[n][n+1]/a[n][n]; for (i=n-1;i>=1;i--) { s=a[i][n+1]; for (j=i+1;j<=n;j++) s=s-a[i][j]*y[j]; if (a[i][i]==0) { printf("Cac phan tu duong cheo cua ma tran bang khongn"); goto mot; } y[i]=s/a[i][i]; } } if (r!=1) for (i=1;i<=n;i++) { if (fabs(y[i])<e*fabs(x[i])) goto ba; } for (i=1;i<=n;i++) x[i]=x[i]-y[i]; printf("n"); }
  • 35. 150 printf("Khong hoi tu sau %d lan lapn",z); goto mot; clrscr(); ba:printf("Vec to nghiemn"); for (i=1;i<=n;i++) printf("%.5fn",(x[i]-y[i])); printf("n"); printf("Do chinh xac cua nghiem la %.5f: n", e); printf("n"); printf("Vec to tri so du :n"); for (i=1;i<=n;i++) printf("%.5fn",(a[i][n+1])); mot:printf("n"); getch(); } void doc() { a[1][1]=3*x[1]*x[1]-3*x[2]*x[4]; a[1][2]=-3*x[2]*x[2]-3*x[1]*x[4]; a[1][3]=0; a[1][4]=-3*x[1]*x[2]; a[1][5]=x[1]*x[1]*x[1]-x[2]*x[2]*x[2]-3*x[1]*x[2]*x[4]-8; a[2][1]=1; a[2][2]=1; a[2][3]=1; a[2][4]=1; a[2][5]=x[1]+x[2]+x[3]+x[4]-5; a[3][1]=-x[1]/sqrt(25-x[1]*x[1]); a[3][2]=0; a[3][3]=8; a[3][4]=0; a[3][5]=sqrt(25-x[1]*x[1])+8*x[3]+4; a[4][1]=2*x[2]*x[3]; a[4][2]=2*x[1]*x[3]; a[4][3]=2*x[1]*x[2]; a[4][4]=-1; a[4][5]=2*x[1]*x[2]*x[3]-x[4]+8; }