資源簡介
只需在input.txt中寫入方程局增廣矩陣 就可以解出方程的解。

代碼片段和文件信息
#include
#include
#include
#include
using?namespace?std;
void?main(){
int?nm;
ifstream?ifile;
ifile.open(“input.txt“);
ifile>>n;
double?a[100][100];
int?ij;
for(i=1;i<=n;i++){
for(j=1;j<=n+1;j++){
ifile>>a[i][j];
}
}
cout<<“輸入方程組介數(shù):“;
cout< cout<<“輸入增廣矩陣:“< for(i=1;i<=n;i++){
for(j=1;j<=n+1;j++){
cout< }
cout< }
for(j=1;j<=n;j++){
double?maximax=0;
for(i=j;i<=n;i++){
if(imax imax=fabs(a[i][j]);
max=a[i][j];
m=i;
}
}
if(fabs(a[j][j])!=max)?{
double?b;
for(int?k=j;k<=n+1;k++){
b=a[j][k];
a[j][k]=a[m][k];
a[m][k]=b;
}
}
for(int?r=j;r<=n+1;r++){
a[j][r]=a[j][r]/max;
}
for(i=j+1;i<=n;i++){
double?c=a[i][j];
if(c==0)??continue;
for(int?s=j;s<=n+1;s++){
a[i][s]=a[i][s]-a[j][s]*c;
}
}
}
for(i=n-1;i>0;i--){
for(j=i+1;j<=n;j++){
a[i][n+1]=a[i][n+1]-a[j][n+1]*a[i][j];
}
}
cout<<“方程組的解是:“< for(int?k=1;k<=n;k++){
cout<<“x“< }
ofstream?ofile;
ofile.open(“output.txt“);
ofile<<“方程組的解是:“< for(?k=1;k<=n;k++){
ofile<<“x“< }
ofile.close();
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3829??2012-08-22?18:04??solution\solution.dsp
?????文件????????524??2012-08-22?03:48??solution\solution.dsw
?????文件??????41984??2012-08-22?23:40??solution\solution.ncb
?????文件??????48640??2012-08-22?23:40??solution\solution.opt
?????文件???????1041??2012-08-22?23:10??solution\solution.plg
?????文件????2382712??2012-08-22?18:00??solution\Debug\solution.pch
?????文件??????25600??2012-08-22?23:10??solution\Debug\solution.pdb
?????文件??????91136??2012-08-23?19:36??solution\Debug\vc60.idb
?????文件?????135168??2012-08-23?19:36??solution\Debug\vc60.pdb
?????文件?????581681??2012-08-23?19:36??solution\Debug\input.exe
?????文件????1147904??2012-08-23?19:36??solution\Debug\input.pdb
?????文件????2116212??2012-08-23?19:12??solution\Debug\input.pch
?????文件?????361473??2012-08-23?19:36??solution\Debug\input.obj
?????文件?????829336??2012-08-23?19:36??solution\Debug\input.ilk
?????文件??????41984??2012-08-23?19:37??solution\input.ncb
?????文件???????1110??2012-08-23?19:36??solution\input.plg
?????文件???????3389??2012-08-23?16:04??solution\input.dsp
?????文件?????????28??2012-08-23?19:36??solution\input.txt
?????文件????????535??2012-08-23?18:15??solution\input.dsw
?????文件???????1349??2012-08-23?19:36??solution\input.cpp
?????文件??????48640??2012-08-23?19:37??solution\input.opt
?????目錄??????????0??2012-08-23?07:44??solution\Debug
?????目錄??????????0??2012-08-23?07:44??solution
-----------?---------??----------?-----??----
??????????????7864275????????????????????23
評論
共有 條評論