Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion prgm_01_01.f03
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ Subroutine PrintMatrix3x3(matrix)
!
write(*,*)' Printing Matrix'
!
ADD CODE HERE
Do i = 1,3
write(*,1000) matrix(i,1), matrix(i,2), matrix(i,3)
End Do
!
!
return
Expand Down
76 changes: 76 additions & 0 deletions prgm_01_02.f03
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Program prgm_01_02
!
! This program reads a 3x3 matrix from a user-provided input file. After the
! file is opened and read, it is closed and then printed.
!
!
implicit none
integer,parameter::inFileUnitA=10,inFileUnitB=11
integer::errorFlag,i
real,dimension(3,3)::matrixInA,matrixInB
character(len=128)::fileNameA,fileNameB
!
!
! Start by asking the user for the name of the data file.
!
write(*,*)' What is the name of the input data file?'
read(*,*) fileNameA
write(*,*)' What is the name of the input data file?'
read(*,*) fileNameB
!
! Open the data file and read matrixInA from that file.
!
open(unit=inFileUnitA,file=TRIM(fileNameA),status='old', &
iostat=errorFlag)
if(errorFlag.ne.0) then
write(*,*)' There was a problem opening the input file.'
goto 999
endIf
do i = 1,3
read(inFileUnitA,*) matrixInA(1,i),matrixInA(2,i),matrixInA(3,i)
endDo
close(inFileUnitA)
!
open(unit=inFileUnitB,file=TRIM(fileNameB),status='old', &
iostat=errorFlag)
if(errorFlag.ne.0) then
write(*,*)' There was a problem opening the input file.'
goto 999
endIf
do i = 1,3
read(inFileUnitB,*) matrixInB(1,i),matrixInB(2,i),matrixInB(3,i)
endDo
close(inFileUnitB)
!
! Call the subroutine PrintMatrix to print matrixInA.
!
call PrintMatrix3x3(matrixInA)
call PrintMatrix3x3(matrixInB)
!
999 continue
End Program prgm_01_02


Subroutine PrintMatrix3x3(matrix)
!
! This subroutine prints a 3x3 real matrix. The output is written to StdOut.
!
implicit none
real,dimension(3,3),intent(in)::matrix
integer::i
!
! Format statements.
!
1000 format(3(2x,f5.1))
!
! Do the printing job.
!
write(*,*)' Printing Matrix'
!
Do i = 1,3
write(*,1000) matrix(i,1), matrix(i,2), matrix(i,3)
End Do
!
!
return
End Subroutine PrintMatrix3x3
82 changes: 82 additions & 0 deletions prgm_01_03.f03
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
Program prgm_01_03
!
! This program reads a 3x3 matrix from a user-provided input file. After the
! file is opened and read, it is closed and then printed.
!
!
implicit none
integer,parameter::inFileUnitA=10,inFileUnitB=11
integer::errorFlag,i
real,dimension(3,3)::matrixInA,matrixInB,matrixProduct
character(len=128)::fileNameA,fileNameB
!
!
! Start by asking the user for the name of the data file.
!
write(*,*)' What is the name of the input data file?'
read(*,*) fileNameA
write(*,*)' What is the name of the input data file?'
read(*,*) fileNameB
!
! Open the data file and read matrixInA from that file.
!
open(unit=inFileUnitA,file=TRIM(fileNameA),status='old', &
iostat=errorFlag)
if(errorFlag.ne.0) then
write(*,*)' There was a problem opening the input file.'
goto 999
endIf
do i = 1,3
read(inFileUnitA,*) matrixInA(1,i),matrixInA(2,i),matrixInA(3,i)
endDo
close(inFileUnitA)
!
open(unit=inFileUnitB,file=TRIM(fileNameB),status='old', &
iostat=errorFlag)
if(errorFlag.ne.0) then
write(*,*)' There was a problem opening the input file.'
goto 999
endIf
do i = 1,3
read(inFileUnitB,*) matrixInB(1,i),matrixInB(2,i),matrixInB(3,i)
endDo
close(inFileUnitB)
!
! Call the subroutine PrintMatrix to print matrixInA.
!
call PrintMatrix3x3(matrixInA)
call PrintMatrix3x3(matrixInB)
!
! Form matrixProduct using the intrinsic function MatMul. Then, print the
! result.
!
matrixProduct = MatMul(matrixInA,matrixInB)
call PrintMatrix3x3(matrixProduct)
!
999 continue
End Program prgm_01_03


Subroutine PrintMatrix3x3(matrix)
!
! This subroutine prints a 3x3 real matrix. The output is written to StdOut.
!
implicit none
real,dimension(3,3),intent(in)::matrix
integer::i
!
! Format statements.
!
1000 format(3(2x,f5.1))
!
! Do the printing job.
!
write(*,*)' Printing Matrix'
!
Do i = 1,3
write(*,1000) matrix(i,1), matrix(i,2), matrix(i,3)
End Do
!
!
return
End Subroutine PrintMatrix3x3
57 changes: 57 additions & 0 deletions prgm_02_01.f03
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Program prgm_02_01

implicit none
real:: m,l
integer:: n1,n2
integer:: ierror=1
real,external:: PIB_1D_T_Element

write(*,*)' What is the mass of the particle M? (must be an integer)'
read(*,*) m
if (m <= 0) then
write(*,*)'The mass cannot be less than or equal to zero.'
stop
end if

write(*,*)'What is the value of the lenght of the box L? (must be &
& an integer)'
read(*,*) l

if (l <= 0.) then
write(*,*)'The box length cannot be less than or equal to zero.'
stop
end if

write(*,*)'What is the value of the quantum number of the first &
& eigenstate n1? (must be an integer)'
read(*,*) n1

write(*,*)'What is the value of the quantum number of the second &
& eigenstate n2? (must be an integer)'
read(*,*) n2

900 Format(1x, 'Kinetic Energy Matrix element', i5,',',i5,' is',f12.5,'.')
!
! Do the printing
!
If (n1 == n2) then
write(*,900) n1, n2, PIB_1D_T_Element(m,l,n1)
else
write(*,'(1x, a, i2, a, i2, a, a)') 'Kinetic Energy Matrix&
& element ', n1, ',', n2, ' is ', '0.'
end if
!
End Program prgm_02_01
!
! (m,l,n1) = (a,b,c)
!
real function PIB_1D_T_Element(a,b,c)
implicit none
real:: a,b
real,parameter:: pi=4.*atan(1.0)
integer:: c

PIB_1D_T_Element =((c**2)*(pi**2))/(2*a*(b**2))
return
!
end function PIB_1D_T_Element
72 changes: 72 additions & 0 deletions prgm_02_02.f03
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
Program prgm_02_02

implicit none
real:: m,l,b
integer:: n1,n2
integer:: ierror=1
real,external:: PIB_1D_T_Element
real,external:: PIB_1D_Modified_V_Element

write(*,*)' What is the mass of the particle M? (must be an integer)'
read(*,*) m
if (m <= 0) then
write(*,*)'The mass cannot be less than or equal to zero.'
stop
end if

write(*,*)'What is the value of the lenght of the box L? (must be &
& an integer)'
read(*,*) l

if (l <= 0.) then
write(*,*)'The box length cannot be less than or equal to zero.'
stop
end if

write(*,*)'What is the value of the quantum number of the first &
& eigenstate n1? (must be an integer)'
read(*,*) n1
n2=n1

write(*,*)'What is the value of b for the potential V(x)=bx? &
&(must be a real)'
read(*,*) b

900 Format(1x, 'Kinetic Energy Matrix element', i5,',',i5,' is',f12.5,'.')
1000 Format(1x, 'Potential Energy Matrix element', i5,',',i5,' is',f12.5,'.')
!
! Do the printing
!
If (n1 == n2) then
write(*,900) n1, n2, PIB_1D_T_Element(m,l,n1)
write(*,1000) n1, n2, PIB_1D_Modified_V_Element(b,l)
else
write(*,'(1x, a, i2, a, i2, a, a)') 'Kinetic Energy Matrix&
& element ', n1, ',', n2, ' is ', '0.'
write(*,'(1x, a, i2, a, i2, a, a)') 'Potential Energy Matrix&
& element ', n1, ',', n2, ' is ', '0.'
end if
!
End Program prgm_02_02
!
! (m,l,n1) = (a,b,c)
!
real function PIB_1D_T_Element(a,b,c)
implicit none
real:: a,b
real,parameter:: pi=4.0*atan(1.0)
integer:: c

PIB_1D_T_Element =((c**2)*(pi**2))/(2*a*(b**2))
return
!
end function PIB_1D_T_Element
!
real function PIB_1D_Modified_V_Element(a,b)
implicit none
real:: a,b

PIB_1D_Modified_V_Element = (a*b)/2.0
return
!
end function PIB_1D_Modified_V_Element
89 changes: 89 additions & 0 deletions prgm_02_03.f03
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
Program prgm_02_03

implicit none
real:: m,l,b
integer:: n1,n2
integer:: ierror=1
real,external:: PIB_1D_T_Element
real,external:: PIB_1D_Modified_V_Element
real,external:: PIB_1D_Modified_Hamiltonian_Element

write(*,*)' What is the mass of the particle M? (must be an integer)'
read(*,*) m
if (m <= 0) then
write(*,*)'The mass cannot be less than or equal to zero.'
stop
end if

write(*,*)'What is the value of the lenght of the box L? (must be &
& an integer)'
read(*,*) l

if (l <= 0.) then
write(*,*)'The box length cannot be less than or equal to zero.'
stop
end if

write(*,*)'What is the value of the quantum number of the first &
& eigenstate n1? (must be an integer)'
read(*,*) n1
n2=n1

write(*,*)'What is the value of b for the potential V(x)=bx? &
&(must be a real)'
read(*,*) b

900 Format(1x, 'Kinetic Energy Matrix element', i5,',',i5,' is',f12.5,'.')
1000 Format(1x, 'Potential Energy Matrix element', i5,',',i5,' is',f12.5,'.')
1100 Format(1x, 'Hamiltonian Matrix element', i5,',',i5,' is',f12.5,'.')
!
! Do the printing
!
If (n1 == n2) then
write(*,900) n1, n2, PIB_1D_T_Element(m,l,n1)
write(*,1000) n1, n2, PIB_1D_Modified_V_Element(b,l)
write(*,1100) n1, n2, PIB_1D_Modified_Hamiltonian_Element&
& (m,l,n1,b)

else
write(*,'(1x, a, i2, a, i2, a, a)') 'Kinetic Energy Matrix&
& element ', n1, ',', n2, ' is ', '0.'
write(*,'(1x, a, i2, a, i2, a, a)') 'Potential Energy Matrix&
& element ', n1, ',', n2, ' is ', '0.'
end if
!
End Program prgm_02_03
!
! (m,l,n1) = (a,b,c)
!
real function PIB_1D_T_Element(a,b,c)
implicit none
real:: a,b
real,parameter:: pi=4.0*atan(1.0)
integer:: c

PIB_1D_T_Element =((c**2)*(pi**2))/(2*a*(b**2))
return
!
end function PIB_1D_T_Element
!
real function PIB_1D_Modified_V_Element(a,b)
implicit none
real:: a,b
PIB_1D_Modified_V_Element = (a*b)/2.0
return
!
end function PIB_1D_Modified_V_Element

real function PIB_1D_Modified_Hamiltonian_Element(m,l,n1,b)
implicit none
real:: m,l,b
integer:: n1
real,external:: PIB_1D_T_Element
real,external:: PIB_1D_Modified_V_Element

PIB_1D_Modified_Hamiltonian_Element = &
&PIB_1D_T_Element(m,l,n1) + PIB_1D_Modified_V_Element(b,l)
return
!
end function PIB_1D_Modified_Hamiltonian_Element