Try compiling the following subroutine:
(1) Realizing matrix triangular decomposition a=lu;
(2) using decomposition factor l,u to solve the ax=b of the equation group (that is, solving the ly=b and then solving ux=y).
Using the above subroutine to solve the linear equation Group AX=BK (k=1,2,...,10), where
A=1 2 4 7 11 16
2 3 5 8 12 17
4 5 6 9 13 18
7 8 9 10 14 19
11 12 13 14 15 20
16 17 18 19 20 21
The B1 is a non-zero six-element vector; If Xk is a ax= BK solution vector, take bk+1=xk/| | xk| |. Please output the result: L;u;bk;xk (k=1,2,...,10). And observe carefully, can find what interesting phenomenon.
Or the calculation method of the work, according to the book formula and flowchart to achieve
Input
6
1 2 4 7 11 16
2 3 5 8 12 17
4 5 6 9 13 18
7 8 9 10 14 19
11 12 13 14 15 20
16 17 18 19 20 21
b Vector any: 6 x 1.
1 1 1 1 1 1
#include <iostream> #include <stdio.h> #include <iomanip> #include <math.h>using namespace std; const int Maxn=1000;int n;double A[MAXN][MAXN];d ouble B[MAXN];d ouble X[MAXN];d ouble y[maxn];//double L[MAXN][MAXN];// Double u[maxn][maxn];void Inita () {printf ("Order of input matrix A:"); cin>>n; printf ("Input matrix a\n"); for (int i=1;i<=n;i++) {for (int j=1;j<=n;j++) {cin>>a[i][j]; }}}void INITB () {printf ("Input b vector \ n"); for (int i=1;i<=n;i++) {cin>>b[i]; }}void Duliteer () {//Compact format gets a=lu double sum; for (int i=2;i<=n;i++) {a[i][1]=a[i][1]/a[1][1]; } for (int k=2;k<=n;k++) {for (int i=k;i<=n;i++) {sum=0; for (int j=1;j<=k-1;j++) {sum+=a[k][j]*a[j][i]; } a[k][i]=a[k][i]-sum; } for (int i=k+1;i<=n;i++) {sum=0; for (int j=1;j<=k-1;j++) {sum+=a[i][j]*a[j][k]; } a[i][k]= (a[i][k]-sum)/a[k][k]; }}}void gety () {y[1]=b[1]; Double sum; for (int k=2;k<=n;k++) {sum=0; for (int j=1;j<=k-1;j++) {sum+=a[k][j]*y[j]; } y[k]=b[k]-sum; }}void Getx () {double sum,m; X[n]=y[n]/a[n][n]; X[0]=fabs (X[n]); for (int k=n-1;k>=1;k--) {sum=0; for (int j=k+1;j<=n;j++) {sum+=a[k][j]*x[j]; } x[k]= (Y[k]-sum)/a[k][k]; X[0]=max (X[0],fabs (x[k)); }}void Xianshi () {cout<<endl; printf ("L and U respectively: \ n"); for (int i=1;i<=n;i++) {for (int j=1;j<=n;j++) {if (i==j) {COUT<<SETW (5) << 1; cout<< ""; } COUT<<SETW (5) <<A[i][j]<< ""; } cout<<endl; }}void output () {printf ("b vector: \ n"); for (int i=1;i<=n;i++) {cout<<b[i]<< ""; } cout<<endl; printf ("x vector: \ n"); for (int i=1;i<=n;i++) {cout<<x[i]<< ""; } Cout<<endl;} int main () {while (1) {Inita (); INITB (); Duliteer (); Gety (); Getx (); Xianshi (); for (int i=1;i<=10;i++) {cout<<endl; printf ("(%d): \ n", i); Output (); for (int j=1;j<=n;j++) {b[j]=x[j]/x[0]; } gety (); Getx (); } cout<<endl; } return 0;}
Duritelfa Solution equations