[Fortran] 纯文本查看 复制代码
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
implicit none
Integer nlhs, nrhs
Integer plhs(*), prhs(*)
Integer mxIsNumeric,mxGetM, mxGetN
Integer mxCreateDoubleMatrix,mxGetPr
Integer N_pr, V_pr
Integer m1,n1,size
real*8 N,V(1000)
m1=mxGetM(prhs(1))
n1=mxGetN(prhs(1))
size=m1*n1
N_pr=mxGetPr(prhs(1))
call mxCopyPtrToReal8(N_pr,N,1)
call LINE(N,V)
plhs(1)=mxCreateDoubleMatrix(1,100,0)
V_pr=mxGetPr(plhs(1))
call mxCopyReal8ToPtr(V,V_pr,100)
return
end
!SUBROUTINE LINE(N,V,m2,n2)
SUBROUTINE LINE(N,V)
!integer m2,n2
DIMENSION P(1000),H0(1000),H(1000),V(1000),X(1000)
X1=1.4
X0=-4.0
DX=(X1-X0)/(N-1.0)
DO I=1,N
X(I)=-4.0+(I-1)*DX
H0(I)=0.5*X(I)*X(I)
H(I)=H0(I)
P(I)=0.0
IF(X(I).GE.-1.0.AND.X(I).LE.1.0)THEN
P(I)=SQRT(1-X(I)*X(I))
ENDIF
ENDDO
CALL SUBAK(N)
CALL VI(N,DX,P,V)
DO I=1,N
H(I)=H(I)+V(I)
ENDDO
STOP
END
SUBROUTINE VI(N,DX,P,V)
DIMENSION P(N),V(N)
COMMON /COMAK/AK(0:1100)
PAI1=0.318309886
C=ALOG(DX)
DO 10 I=1,N
V(I)=0.0
DO 10 J=1,N
IJ=IABS(I-J)
10 V(I)=V(I)+(AK(IJ)+C)*DX*P(J)
DO I=1,N
V(I)=-PAI1*V(I)
ENDDO
RETURN
END
SUBROUTINE SUBAK(MM)
COMMON /COMAK/AK(0:1100)
DO 10 I=0,MM
10 AK(I)=(I+0.5)*(ALOG(ABS(I+0.5))-1.)-(I-0.5)*(ALOG(ABS(I-0.5))-1.)
RETURN
END