yf881031 发表于 2011-3-6 11:54:06

请教一个在Fortran中调用matlab的问题

我在编了段小程序,希望用matlab中方便的矩阵功能来处理数据:
program eigenvalue
integer engOpen,engGetMatrix,mxCreateFull,mxGetpr,mxGetpi !输入函数
integer engPutMatrix,engEvalString,engClose!输出函数
integer ep,temp_Q,temp_R,temp_T,temp_N,temp_p,temp_ci
integer temp_a1,temp_a2,temp_a3,temp_b1,temp_b2,temp_b3 !指针
real*8 Q(3,3),R(3,3),T(3,3),N(6,6)
!complex p(6),ci(6),a1(3),a2(3),a3(3),b1(3),b2(3),b3(3)
do i=1,3
do j=1,3
   Q(i,j)=1.
   R(i,j)=2.
   T(i,j)=0.
end do
end do
T(1,1)=8. ; T(2,2)=9. ; T(3,3)=5.
ep=engOpen('Matlab')
temp_Q=mxCreateFull(3,3,0) ; temp_R=mxCreateFull(3,3,0) ; temp_T=mxCreateFull(3,3,0)
call mxSetName(temp_Q,'Q') ; call mxSetName(temp_R,'R') ; call mxSetName(temp_T,'T')
call mxCopyReal8ToPtr(Q,mxGetPr(temp_Q),9) ; call mxCopyReal8ToPtr(R,mxGetPr(temp_R),9) ; call mxCopyReal8ToPtr(T,mxGetPr(temp_T),9)
call engPutMatrix(ep,temp_Q) ; call engPutMatrix(ep,temp_R) ; call engPutMatrix(ep,temp_T)
call engEvalString(ep,'N1=-inv(T)*R";')
call engEvalString(ep,'N2=inv(T);')
call engEvalString(ep,'N3=R*inv(T)*R"-Q;')
call engEvalString(ep,'N4=N1";')
call engEvalString(ep,'N=[N1,N2;')
call engEvalString(ep,'N3,N4];')
temp_N=engGetMatrix(ep,'N')
!call mxCopyPtrToReal8(mxGetpr(temp_N),N,36)    注释掉,不然会出错
!call engClose(ep)
end
在matlab中执行的代码仅红字,但是在运行后,查看matlab中矩阵的值,仅仅找到Q,R,T,N2,没有N1,N3,N4,N的值,我想这才导致了蓝字部分的出错(如不注释,会有错)。但是为什么没有N1,N3,N4,N的值呢,望高手指点。

yf881031 发表于 2011-3-6 19:56:42

呵呵,自己解决了,转置不用''而用transpose,组合矩阵的命令写在一行N=,才学这个,犯低级错误了
页: [1]
查看完整版本: 请教一个在Fortran中调用matlab的问题