Hi all,(adsbygoogle = window.adsbygoogle || []).push({});

I encountered a problem while running a FORTRAN 90 program, which appears (to me) to be quite surprising. Can someone please explain the following things:

1. Why the (4,1) element of the beta matrix is 5.0 instead of being 2.0 ??

2. Why the (5,8) element of the beta matrix is non-zero instead of being zero ??

Here comes the program with the results at the end:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

PROGRAM hamiltonian

IMPLICIT NONE

INTEGER :: N,i,j,k

REAL, ALLOCATABLE, DIMENSION (:,:) :: alpha,beta

COMPLEX, ALLOCATABLE, DIMENSION (:,:) :: hk

N=8

ALLOCATE (alpha(N,N),beta(N,N),hk(N,N))

alpha=0.

beta=0.

hk=(0.,0.)

DO k=0,(N-4)/4

alpha(4*k+1,4*k+1-3)=5.

alpha(4*k+1,4*k+1+1)=5.

alpha(4*k+2,4*k+2-1)=5.

alpha(4*k+2,4*k+2+1)=5.

alpha(4*k+2,4*k+2+3)=5.

alpha(4*k+3,4*k+3-1)=5.

alpha(4*k+3,4*k+3+1)=5.

alpha(4*k+3,4*k+3+5)=5.

alpha(4*k+4,4*k+4-5)=5.

alpha(4*k+4,4*k+4-1)=5.

beta(4*k+4,4*k+4-3)=2.

END DO

DO i=1,N

OPEN (UNIT=10,FILE='alpha.dat')

WRITE(10,100)(alpha(i,j),j=1,N)

100 FORMAT(8(3X,F3.1))

OPEN (UNIT=20,FILE='beta.dat')

WRITE(20,200)(beta(i,j),j=1,N)

200 FORMAT(8(3X,F3.1))

END DO

CLOSE (10)

CLOSE (20)

END PROGRAM

============================================================

~ RESULTS ~

alpha.dat :

0.0 5.0 0.0 0.0 0.0 0.0 0.0 0.0

5.0 0.0 5.0 0.0 5.0 0.0 0.0 0.0

0.0 5.0 0.0 5.0 0.0 0.0 0.0 5.0

0.0 0.0 5.0 0.0 0.0 0.0 0.0 0.0

0.0 5.0 0.0 0.0 0.0 5.0 0.0 0.0

0.0 0.0 0.0 0.0 5.0 0.0 5.0 0.0

0.0 0.0 0.0 0.0 0.0 5.0 0.0 5.0

0.0 0.0 5.0 0.0 0.0 0.0 5.0 0.0

beta.dat :

0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

5.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

0.0 0.0 0.0 5.0 0.0 0.0 0.0 0.0

0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

**Physics Forums - The Fusion of Science and Community**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# FORTRAN 90: Peculiar bug (?)

Loading...

Similar Threads for FORTRAN Peculiar | Date |
---|---|

If statement for Monte Carlo integration | Sunday at 7:46 AM |

C/++/# How to use C++ in studying calculus | Apr 3, 2018 |

Fortran How to buy Fortran Programming Software Commersial License | Jan 30, 2018 |

Fortran Fortran for Computational Fluid Dynamics Problems | Jan 11, 2018 |

Fortran [Fortran] something very peculiar | Oct 21, 2014 |

**Physics Forums - The Fusion of Science and Community**