xiuyouxu
建议找一本数值分析的书看一下,里面有具体的算法,我以前实现过,其他语言的,没有用c语言做过.
cxdc
引用回帖:
xiuyouxu at 2012-05-03 21:28:11:
建议找一本数值分析的书看一下,里面有具体的算法,我以前实现过,其他语言的,没有用c语言做过.
# include
# include
void main()
{
float m,A[9];
float L[6];
printf("璇疯緭鍏ョ煩闃�: n ");
scanf("%f %f %fn%f %f %fn%f %f %fn",&A[0],&A[1],&A[2],&A[3],&A[4],&A[5],&A[6],&A[7],&A[8]);
printf("璇疯緭鍏ュ�?璁歌宸�:m=");
scanf("%f",&m);
if
A[0]>m&&(A[0]*A[4]-A[1]*A[3]>m)&&(A[6]*A[4]*A[2]+A[0]*A[7]*A[5]+A[1]*A[3]*A[8]-A[0]*A[4]*A[8]-A[1]*A[6]*A[5]-A[2]*A[3]*A[7]>m)&&(A[1]==A[3])&&(A[2]==A[6])&&(A[5]==A[7])
{
L[0]=sqrt(A[0]);
L[1]=A[3]/L[0];
L[3]=A[6]/L[0];
L[2]=sqrt(A[4]-L[1]*L[1]);
L[4]=(A[7]-L[3]*L[1])/L[2];
L[5]=sqrt(A[8]-L[3]*L[3]-L[4]*L[4]);
printf("鎵�姹傜煩闃典负L=n %f 0 0n%f %f 0n%f %f %fn",L[0],L[1],L[2],L[3],L[4], L[5]);
}
else
printf("杈撳叆鏈夎锛岃妫�鏌�");
}
璋冭瘯杩?琛岋細
1>.Debugshiyan.exe.intermediate.manifest : general error c1010070: Failed to load and parse the manifest. {_~0p'1a@'7v par 1>Build log was saved at "file://e:360data閲?瑕?鏁版?甛妗岄?shiyanshiyanDebugBuildLog.htm"
1>shiyan - 1 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
宸ョ▼鏃犳硶寤虹珛
棰勬湡鏁堟灉锛�
璇疯緭鍏ョ煩闃碉細
1 2 3
2 4 5
3 5 6
璇疯緭鍏ュ�?璁歌宸細m=1e-6
杈撳叆鏈夎锛岃妫�鏌�
璇疯緭鍏ョ煩闃碉細
5 2 -4
2 1 -2
-4 -2 5
璇疯緭鍏ュ�?璁歌宸細m=1e-6
鎵�姹傜煩闃礚=
2.236068 0 0
0.894427 0.4472136 0
-1.788854 -0.894427 1
鎴戠殑绠楁硶杩?琛屼�?閫氳繃鍟婏紝鑰屼笖鏍规湰鏈兘瀹炵幇閽堝浠绘�?闃舵鐨勭煩闃点�傘�傘�傛眰澶х甯繖~
,
cxdc
引用回帖:
xiuyouxu at 2012-05-03 21:28:11:
建议找一本数值分析的书看一下,里面有具体的算法,我以前实现过,其他语言的,没有用c语言做过.
# include
# include
void main()
{
float m,A[9];
float L[6];
printf("请输入矩阵: n ");
scanf("%f %f %fn%f %f %fn%f %f %fn",&A[0],&A[1],&A[2],&A[3],&A[4],&A[5],&A[6],&A[7],&A[8]);
printf("请输入允许误差:m=");
scanf("%f",&m);
if
A[0]>m&&(A[0]*A[4]-A[1]*A[3]>m)&&(A[6]*A[4]*A[2]+A[0]*A[7]*A[5]+A[1]*A[3]*A[8]-A[0]*A[4]*A[8]-A[1]*A[6]*A[5]-A[2]*A[3]*A[7]>m)&&(A[1]==A[3])&&(A[2]==A[6])&&(A[5]==A[7])
{
L[0]=sqrt(A[0]);
L[1]=A[3]/L[0];
L[3]=A[6]/L[0];
L[2]=sqrt(A[4]-L[1]*L[1]);
L[4]=(A[7]-L[3]*L[1])/L[2];
L[5]=sqrt(A[8]-L[3]*L[3]-L[4]*L[4]);
printf("所求矩阵为L=n %f 0 0n%f %f 0n%f %f %fn",L[0],L[1],L[2],L[3],L[4], L[5]);
}
else
printf("输入有误,请检查");
}
调试运行:
1>.Debugshiyan.exe.intermediate.manifest : general error c1010070: Failed to load and parse the manifest. {_~0p'1a@'7v par 1>Build log was saved at "file://e:360data重要数据桌面shiyanshiyanDebugBuildLog.htm"
1>shiyan - 1 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
工程无法建立
失败了,而且达不到针对任意阶次矩阵的效果!
xiuyouxu
matlab里面直接用root函数就可以了, 下面是我写的c++的:
// 定义Matrix类(略)
// m*n阶0矩阵
void Matrix::zeros(int m,int n,double** a){
for(int i=0;i
for(int j=0;j
a[j]=0;
}
}
}
// n为矩阵的阶
void Matrix::root(int n,double** A,double** L){
zeros(n,n,L);
for(int i=0;i
for(int j=0;j
double sum=0;
for(int k=0;k
sum+=L[k]*L[j][k];
}
L[j]=(A[j]-sum)/L[j][j];
}
double sum=0;
for(int k=0;k
sum+=L[k]*L[k];
}
L=sqrt(A-sum);// 显然 A-sum<0时不是正定矩阵
}
}
cxdc
引用回帖:
xiuyouxu at 2012-05-03 22:29:03:
matlab里面直接用root函数就可以了, 下面是我写的c++的:
// 定义Matrix类(略)
// m*n阶0矩阵
void Matrix::zeros(int m,int n,double** a){
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
a=0; ...
还是运行不通。。。
xiuyouxu
晕,这个回复框不能放代码啊,有一部分代码被替换掉了,代码里不能出现,会被替换掉
xiuyouxu
看看这样行不行 [i]