- #1
KarAnw
- 3
- 0
Hello, I am new in the field of FORTRAN. I started to write a code using Newton Raphson method. Below is the code of main program portion only. During my calculation, I have found that my results are not converging, Any help or advice will be highly appreciated in this case.
Thank you for the effort of helping in advance. Program Free_energy
Implicit None
Integer:: i,j,l,k
Double Precision Gmic,U,Phi
Double Precision s,Uderv,cc,DG0,cf,ctot1,
& Keff,Cagg,ctot,sum,Cagg1,cnew,
& Cagg2,cctot1,kapp,error,Csalt,Csalt1,
& cext
Double precision :: Nelec
Double precision :: Nwat
Double precision :: Nlig
ctot = 1D0
cf=ctot/2
cext = 0.01
sum=0.0
DG0 = -100.0
Do While(DG0.le.20)
do i=0,2
do j=0,10
do l=0,10
Nelec=i
Nwat=j
Nlig=l
Keff=dexp(-Gmic(Nelec,Nwat,Nlig)-Nelec*DG0)
Cagg=Keff*((cf)**Nlig)
Cagg1=sum+Nlig*Cagg
Cagg2=sum+(Nlig**2)*Cagg
enddo
enddo
enddo
ctot1=ctot-Cagg1
cctot1=ctot-Cagg2
cnew = cf-(ctot1/cctot1)
error = abs((cnew-cf)/cnew)
cf = cnew
write(72,*) cf, error
if(error.lt.1D-7) exit
Csalt1 = 0.0
do i=0,2
do j=0,10
do l=0,10
Nelec=i
Nwat=j
Nlig=l
Keff = dexp(-Gmic(Nelec,Nwat,Nlig))
Csalt = Csalt1+Keff*((cf)**Nlig)*Nelec
enddo
enddo
enddo
Kapp = Csalt/cext
write(70,*) DG0, -log(kapp)/2
write(72,*) cf, -log(kapp)/2
DG0 = DG0 + 0.1
enddo
Thank you for the effort of helping in advance. Program Free_energy
Implicit None
Integer:: i,j,l,k
Double Precision Gmic,U,Phi
Double Precision s,Uderv,cc,DG0,cf,ctot1,
& Keff,Cagg,ctot,sum,Cagg1,cnew,
& Cagg2,cctot1,kapp,error,Csalt,Csalt1,
& cext
Double precision :: Nelec
Double precision :: Nwat
Double precision :: Nlig
ctot = 1D0
cf=ctot/2
cext = 0.01
sum=0.0
DG0 = -100.0
Do While(DG0.le.20)
do i=0,2
do j=0,10
do l=0,10
Nelec=i
Nwat=j
Nlig=l
Keff=dexp(-Gmic(Nelec,Nwat,Nlig)-Nelec*DG0)
Cagg=Keff*((cf)**Nlig)
Cagg1=sum+Nlig*Cagg
Cagg2=sum+(Nlig**2)*Cagg
enddo
enddo
enddo
ctot1=ctot-Cagg1
cctot1=ctot-Cagg2
cnew = cf-(ctot1/cctot1)
error = abs((cnew-cf)/cnew)
cf = cnew
write(72,*) cf, error
if(error.lt.1D-7) exit
Csalt1 = 0.0
do i=0,2
do j=0,10
do l=0,10
Nelec=i
Nwat=j
Nlig=l
Keff = dexp(-Gmic(Nelec,Nwat,Nlig))
Csalt = Csalt1+Keff*((cf)**Nlig)*Nelec
enddo
enddo
enddo
Kapp = Csalt/cext
write(70,*) DG0, -log(kapp)/2
write(72,*) cf, -log(kapp)/2
DG0 = DG0 + 0.1
enddo