主题:[讨论]Fortran log domain error
jingjingzouji [专家分:0] 发布于 2012-11-27 21:17:00
紧急求助啊,下面的程序出现log domain error. 请大家帮忙怎么解决啊!急啊!非常感谢!!!
Program main
integer :: ix,iy
real(8),dimension(1,1,5,5) :: xp,x
real(8),dimension(1:2,5,5) :: phi
xp(1,1,1,1)=0.2
x(1,1,1,1)=0.2
phi(1,1,1)=1
phi(2,1,1)=0
do ix=1,5
do iy=1,5
xp(1,1,ix,iy)=xp(1,1,ix,iy)+0.01
x(1,ix,iy,1)= x(1,ix,iy,1)+ 0.05
phi(1,ix,iy)=phi(1,ix,iy)-0.001
phi(1,ix,iy)=phi(2,ix,iy)+0.001
call calculation (xp(1,1,ix,iy),x(1,ix,iy,1),phi(1,ix,iy),phi(2,ix,iy))
xp(1,2,ix,iy)=(x(1,ix,iy,1)-phi(1,ix,iy)*xp(1,1,ix,iy))/phi(2,ix,iy)
end do
end do
end program main
subroutine calculation (x,xc,phi1,phi2)
integer :: k
real(8) :: tol,x,x0,xc,f,df,phi1,phi2
f(x)=1.06366481d10+7.94800172d9+1.72992961d9*log(abs(x))-1.72992961d9*log(abs(1-x))-1.182988286d10*(1-2*x)+2.75714286d9*(6*x-6*x**2-1)+3.083731429d9*(24*x**2-10*x-16*x**3+1)-1d11*(xc-phi1*x)/phi2 + 9.229804981d10
df(x)=2*1.182988286d10+1.72992961d9/x/(1-x)+2.75714286d9*(6-12*x)+3.083731429d9*(48*x-10-48*x**2)+1d11*phi1/phi2
tol=1e-6
x0=0.2d0
k=0
10 k=k+1
x=x0-f(x0)/df(x0)
if(abs(x-x0).lt.tol)goto 20
x0= x
goto 10
20 write(*,*) x
end subroutine calculation
Program main
integer :: ix,iy
real(8),dimension(1,1,5,5) :: xp,x
real(8),dimension(1:2,5,5) :: phi
xp(1,1,1,1)=0.2
x(1,1,1,1)=0.2
phi(1,1,1)=1
phi(2,1,1)=0
do ix=1,5
do iy=1,5
xp(1,1,ix,iy)=xp(1,1,ix,iy)+0.01
x(1,ix,iy,1)= x(1,ix,iy,1)+ 0.05
phi(1,ix,iy)=phi(1,ix,iy)-0.001
phi(1,ix,iy)=phi(2,ix,iy)+0.001
call calculation (xp(1,1,ix,iy),x(1,ix,iy,1),phi(1,ix,iy),phi(2,ix,iy))
xp(1,2,ix,iy)=(x(1,ix,iy,1)-phi(1,ix,iy)*xp(1,1,ix,iy))/phi(2,ix,iy)
end do
end do
end program main
subroutine calculation (x,xc,phi1,phi2)
integer :: k
real(8) :: tol,x,x0,xc,f,df,phi1,phi2
f(x)=1.06366481d10+7.94800172d9+1.72992961d9*log(abs(x))-1.72992961d9*log(abs(1-x))-1.182988286d10*(1-2*x)+2.75714286d9*(6*x-6*x**2-1)+3.083731429d9*(24*x**2-10*x-16*x**3+1)-1d11*(xc-phi1*x)/phi2 + 9.229804981d10
df(x)=2*1.182988286d10+1.72992961d9/x/(1-x)+2.75714286d9*(6-12*x)+3.083731429d9*(48*x-10-48*x**2)+1d11*phi1/phi2
tol=1e-6
x0=0.2d0
k=0
10 k=k+1
x=x0-f(x0)/df(x0)
if(abs(x-x0).lt.tol)goto 20
x0= x
goto 10
20 write(*,*) x
end subroutine calculation