[求助]各位大侠帮我看看我的程序有什么问题啊
<P>我在做卡尔曼滤波器的基本软件。有个求矩阵逆的地方,我用了全选主元高斯约当法。可4阶方阵还能出个结果(但结果不对);到了5阶,编译时依然没错,就是运行时老出“can't run target cpu”之类到话。我用到是DSP的软件CCS,c6701 simulater map1各位高手帮我看看吧,先谢谢了!!!<BR><BR>#include "stdio.h"<BR>#define N 5//矩阵维数<BR>extern int dcinv(double a[],int n);</P><P>void main()<BR>{<BR> int i,j;<BR> /*static double x={1,0,0,0,0,0,<BR> 0,1,0,0,0,0,<BR> 0,0,1,0,0,0,<BR> 0,0,0,1,0,0,<BR> 0,0,0,0,1,0,<BR> 0,0,0,0,0,1};*/<BR> static double x={0,0,0,1,2,<BR> 0,0,0,2,3,<BR> 1,1,0,0,0,<BR> 0,1,1,0,0,<BR> 0,0,1,0,0,};<BR> /*inverse of x=00 1 -11<BR> 00 01 -1<BR> 00 001<BR> -3 2 000<BR> 2 -1 000*/<BR> /*double x={3,-2,0,0,<BR> 5,-3,0,0,<BR> 0, 0,3,4,<BR> 0, 0,1,1};*/<BR> /*inverse of x=-320 0 <BR> -530 0 <BR> 00 -1 4<BR> 001 -3*/<BR> double y;<BR> for(i=0;i<N;i++)<BR>for(j=0;j<N;j++)<BR> y=x; <BR> printf("begin\n");<BR> i=dcinv(x,N);<BR> printf("end\n");<BR> if(i!=0)<BR>{<BR>printf("mat x is:\n");<BR>for(i=0;i<N;i++)<BR> {<BR> for(j=0;j<N;j++)<BR> printf("%e",y);<BR> printf("\n");<BR> }<BR>printf("\n");<BR><BR>printf("mat x-1 is:\n");<BR>for(i=0;i<N;i++)<BR> {<BR> for(j=0;j<N;j++)<BR> printf("%e",x);<BR> printf("\n");<BR> }<BR>printf("\n");<BR>}<BR>}</P>
<P><BR> </P> <P>这是求逆子函数<BR>#include "stdio.h"<BR>#include "math.h"<BR>#include "stdlib.h"</P>
<P>int dcinv(double a[],int n)<BR>{<BR>int *is,*js,i,j,k,l,u,v;<BR>double d,p;<BR>is=malloc(n*sizeof(int));<BR>js=malloc(n*sizeof(int));<BR>for(k=0;k<=n-1;k++)<BR> {<BR> d=0.0;<BR> for(i=k;i<=n-1;i++)<BR> for(j=k;j<=n-1;j++)<BR>{l=i*n+j;<BR>p=fabs(a);<BR>if(p>d){d=p;is=i;js=j;}<BR>}<BR>/*选出第k行第k列的右下角子阵中绝对值最大<BR>的元素,放入d中,并将此元素的行列号存入<BR>is、js中*/<BR> if(d+1.0==1.0)<BR>{free(is);free(js);printf("err**not inv\n");<BR>return(0);<BR>}<BR>/*若A为奇异矩阵,则求逆失败,返回错误信息*/<BR> if(is!=k)<BR>for(j=0;j<=n-1;j++)<BR> {u=k*n+j;v=is*n+j;<BR> p=a;a=a;a=p;<BR> }//行交换<BR> if(js!=k)<BR>for(i=0;i<=n-1;i++)<BR> {u=i*n+k;v=i*n+js;<BR> p=a;a=a;a=p;<BR> }//列交换<BR> /*通过行交换列交换将最大绝对值元素换到主元素位置上*/<BR> l=k*n+k;<BR> a=1.0/a;<BR> /*a=1/a*/<BR> for(j=0;j<=n-1;j++)<BR>if(j!=k)<BR> {u=k*n+j;a=a*a;}<BR> /*a=a*a*/<BR> for(i=0;i<=n-1;i++)<BR>if(i!=k)<BR> for(j=0;j<=n-1;j++)<BR> if(j!=k)<BR> {u=i*n+j;<BR> a=a-a*a;<BR> }<BR> /*a=a-a*a*/<BR> for(i=0;i<=n-1;i++)<BR>if(i!=k)<BR> {u=i*n+k;a=-a*a;<BR> }<BR> /*a=-a*a*/<BR> /*for(i=0;i<=n-1;i++)<BR>for(j=0;j<=n-1;j++)<BR> printf("a[%n][%n]=%e",i,j,a);<BR>printf("\n");*/<BR> }<BR>for(k=n-1;k>=0;k--)<BR> {if(js!=k)<BR>for(j=0;j<=n-1;j++)<BR> {u=k*n+j;v=js*n+j;<BR> p=a;a=a;a=p;<BR> }<BR> if(is!=k)<BR>for(i=0;i<=n-1;i++)<BR> {u=i*n+k;v=i*n+is;<BR> p=a;a=a;a=p;<BR> }<BR> }<BR>free(is);<BR>free(js);<BR>return(1);<BR>}</P>
页:
[1]