|Jan18-09, 10:35 PM||#1|
Checking programming code: fortran 95
Can anyone be kind enough to check what's wrong with my source code?
Here's the project: http://www.dur.ac.uk/3h.physics/proj...nsmission.html
You can skip the introduction bits.
I'm stuck at the last question on Calculation Part I. I did the source code independently and it works for single barrier and double barrier. But when I change it to N barriers, it didn't work, not even for single barrier.
Here's my source code:
! Transmission of Electronics through a Semiconductor Barrier Structure for N barriers.
double precision:: V, L, r1, t1, s1
double complex,dimension(2,2):: M, F, A_i, i_A, B_i
double complex:: k_A, k_B, m_A, m_B, zi
integer:: i, N, j, a, b, p, x
double precision:: E, delta_E, L_j
! Define the values of m_A, m_B, k_A, k_B, V, L_j
! 1 Bohr radius=0.53 Angstroms
write(*,*)'Please enter the number of barriers, x, where x is an integer more than zero.'
N=2*x ! N is the number of interface.
! Do loop. To varies the values of E from 0 to 1.0eV.
if (E.ge.V) then
! Computing for N interfaces.
! Define identity matrix M.
M(2,2)=1 ! M should be identity matrix.
! Test if b is even or odd.
if (((dble(b/2)-0.001d0).lt.(dble(b)/2.0d0)) .and. ((dble(b)/2.0d0).lt.(dble(b/2)+0.001d0))) then
print*, 'b is even', b
print*, 'b is odd',b
! Calculating Reflection coefficient,r1 and Transmission coefficient,t1.
! Calculate the resultant reflection and transmission coefficients
! Let s1 be the sum of r1 and t1, s1=r1+t1
write(10,10) E, r1, t1, s1
end program project ! end program project
! On return to the calling program, the matrix B contains the inverse of 2x2 matrix A
! C is the determinant of A.
double complex,dimension(2,2),intent(in):: A
double complex,dimension(2,2),intent(out):: B
double complex:: C
if (C.ne.(0d0,0d0)) then
write(*,*) 'Subroutine invert2x2 has failed.'
end subroutine invert2x2
! On return to the calling program, the matrix C contains the multiplication of A and B
double complex, dimension(2,2), intent(in):: A, B
double complex, dimension(2,2), intent(out):: C
end subroutine multiply2x2
double precision:: L_j
double complex:: zi, k_A, k_B, m_A, m_B
double complex, dimension(2,2):: A_i
print*, k_A, m_A, L_j
end subroutine A_matrix
|Jan19-09, 12:31 AM||#2|
Did the program refuse to compile?
Did it compile, but crashed when you ran it? What error messages, if any?
Did it run, but give incorrect results? What input data did you give it, what results did you expect, and what did you actually get?
|Jan19-09, 07:47 AM||#3|
Thanks for the reply. I've found the mistake now. Instead of using my own subroutine for matrix multiplication, matmul(a,b) is much more convenient way and it gives the answer. For God sake, my demonstrators didn't even tell me that!!
Previously, it did run. The programme didn't produce the expected answer.
Thanks again for taking the trouble to read through it, although I still don't understand what's wrong with my subroutine multiply2x2.
|Similar Threads for: Checking programming code: fortran 95|
|Code::Blocks and Fortran||Programming & Comp Sci||1|
|Help me to write fortran code||Programming & Comp Sci||1|
|Fortran code(Do-Loops) for the region||Programming & Comp Sci||0|
|Convert latex code to fortran code?||Math & Science Software||1|
|code for checking for pythogrean triples.||Programming & Comp Sci||2|