内容发布更新时间 : 2024/12/23 5:42:16星期一 下面是文章的全部内容请认真阅读。
#include
int n,i,j,k,m; cout<<\输入维数:\ cin>>n;
double **A=new double*[(n+1)]; for(i=1;i<=n;i++)
A[i]=new double[n+1]; double *b=new double[n+1]; double *x=new double[n+1]; double *y=new double[n+1];
cout<<\输入系数对称正定矩阵A[][]:\ for(i=1;i<=n;i++) for(j=1;j<=n;j++) cin>>A[i][j]; cout<<\输入向量b[]:\ for(i=1;i<=n;i++)
}
cin>>b[i]; cout< for(k=1;k<=n;k++) { double sum=0; for(m=1;m<=k-1;m++) { sum=sum+pow(A[k][m],2.0); } sum=A[k][k]-sum; A[k][k]=sqrt(sum); for(i=k+1;i<=n;i++) { double temp1=0; for(m=1;m<=k-1;m++) { temp1=temp1+A[i][m]*A[k][m]; } temp1=A[i][k]-temp1; A[i][k]=temp1/A[k][k]; } double temp2=0; for(m=1;m<=k-1;m++) { temp2=temp2+A[k][m]*y[m]; } y[k]=(b[k]-temp2)/A[k][k]; } x[8]=y[8]/A[8][8]; for(k=n-1;k>=1;k--) { double temp3=0; for(m=k+1;m<=n;m++) { temp3=temp3+A[m][k]*x[m]; } x[k]=(y[k]-temp3)/A[k][k]; } cout<<\输出结果向量x[]:\ for(i=1;i<=n;i++) cout< 3、三对角形线性方程组 ?4?100000000??x1??7???14?10000000??x??5?2???????0?14?1000000??x3???13???????x00?14?1000002???4????000?14?10000??x5??6? ???? = ?? ?0000?14?1000??x6???12??00000?14?100??x??14?7???????000000?14?10??x8???4??0000000?14?1??x??5?9?????????00000000?14?????5???x10??x= ( 2, 1, -3, 0, 1, -2, 3, 0, 1, -1 ) 追赶法 *T #include int n,i; cout<<\输入系数矩阵的维数:\ cin>>n; double *a=new double[n+1]; double *c=new double[n+1]; double *d=new double[n+1]; double *b=new double[n+1]; double *x=new double[n+1]; double *y=new double[n+1]; cout<<\输入系数矩阵A[]数据:\ for(i=1;i<=n;i++) cin>>a[i]; for(i=1;i<=n;i++) cin>>c[i]; for(i=1;i<=n;i++) cin>>d[i]; cout<<\输入b[] :\ } for(i=1;i<=n;i++) cin>>b[i]; for(i=1;i<=n-1;i++) { c[i]=c[i]/a[i]; a[i+1]=a[i+1]-d[i+1]*c[i]; } cout<<\输出解向量a[]:\ for(i=1;i<=n;i++)cout< for(i=1;i<=n;i++)cout< y[i]=(b[i]-d[i]*y[i-1])/a[i]; } cout<<\输出解向量y[]:\ for(i=1;i<=n;i++)cout< for(i=n-1;i>=1;i--) { x[i]=y[i]-c[i]*x[i+1]; } cout<<\输出解向量x[]:\ for(i=1;i<=n;i++)cout<