0
我有以下的算法,這裏非常strangly工作,明確的目標代碼矩陣分解算法
#include <iostream>
using namespace std;
#define maxn 1000
#define n 3
double sum=0;
double sum1=0;
double a[maxn][maxn];
double l[maxn][maxn];
double u[maxn][maxn];
void read(){
for(int i=1;i=n;i++){
for(int j=1;j<=n;j++){
cin>>a[i][j];
}
}
}
void decomposition(){
for(int i=1;i<=n;i++)
l[i][1]=a[i][1];
for(int j=1;j<=n;j++)
u[1][j]=a[1][j]/l[1][1];
for(int j=2;j<=n;j++){
for(int i=j;i<=n;i++){
for(int k=1;k<j;k++){
sum+=l[i][k]*u[k][j];
}
l[i][j]=a[i][j]-sum;
}
u[j][j]=1;
for(int i=j+1;i<=n;i++){
for(int k=1;k<j;k++){
sum1+=l[j][k]*u[k][i];
}
u[j][i]=(a[j][i]-sum1)/l[j][j];
}
}
}
void print(){
cout<<" L matrix "<<endl;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cout<<l[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
cout<<" U matrix "<<endl;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cout<<u[i][j]<<" ";
}
cout<<endl;
}
}
int main(){
cout<<"enter the matrix "<<endl;
read();
cout<<endl;
decomposition();
cout<<"print twwo matrix "<<endl;
print();
return 0;
}
,但是當我輸入矩陣,比如我想分解這個矩陣
3 -1 2
1 2 3
2 -2 -1
程序不顯示輸出,只需要再次輸入一些輸入,我在這裏看不到我的代碼中需要輸入更多的矩陣或數據,那麼問題是什麼?
我會說我的編輯代碼看起來會更好,然後這個:D,這是笑話 –
對不起,意外地刪除了包含的間距。固定的 – Hasturkun
數組索引基於零或基於你的編程語言? – MBo