Matlab Code For Plate Diffusion Report
Matlab Code For Plate Diffusion Report
Max Kondrath
!HW #7
!3/20/12
program Plate7
real, dimension(16,11)::heat
real, dimension(500000) :: error
integer i, j, counter, dummy, dummer
real dx, relax, maxError
relax = 0.5
!0.5,1.0 or 1.5
oldval = 0
dx = 1
i = 1
j = 1
counter = 0
dummy = 1
dummer = 1
maxError = 100
!loop for i and j to run through internal node for top sectional rectangle
do j = 2,6
do i = 2,15
oldval = heat(i,j)
heat(i,j) = (heat(i+1,j) + heat(i-1,j) + heat(i,j+1)+ heat(i,j-1))/4
heat(i,j) = (relax)*heat(i,j) + (1-relax)*oldval
error(dummy) = ((heat(i,j) - oldval)/heat(i,j))*100
dummy = dummy + 1
end do
end do
!loop for i and j to run through internal nodes for bottom sectional rectangle
do j = 7,10
do i = 2,11
oldval = heat(i,j)
heat(i,j) = (heat(i+1,j) + heat(i-1,j) + heat(i,j+1)+ heat(i,j-1))/4
heat(i,j) = (relax)*heat(i,j) + (1-relax)*oldval
error(dummy) = ((heat(i,j) - oldval)/heat(i,j))*100
dummy = dummy + 1
end do
end do
!customized iterations-------------------------------------------------------------------!extra nodes that have been avoided until this point in the iteration process ( for
simplicity )
dummy = dummy + 1
i = 12
j= 7
oldval = heat(i,j)
heat(i,j) = (heat(i+1,j) + heat(i-1,j) + heat(i,j+1)+ heat(i,j-1))/4
heat(i,j) = (relax)*heat(i,j) + (1-relax)*oldval
error(dummy) = ((heat(i,j) - oldval)/heat(i,j))*100
dummy = dummy + 1
i = 13
j=7
oldval = heat(i,j)
heat(i,j) = (heat(i+1,j) + heat(i-1,j) + heat(i,j+1)+ heat(i,j-1))/4
heat(i,j) = (relax)*heat(i,j) + (1-relax)*oldval
error(dummy) = ((heat(i,j) - oldval)/heat(i,j))*100
dummy = dummy + 1
i = 12
j=8
oldval = heat(i,j)
heat(i,j) = (heat(i+1,j) + heat(i-1,j) + heat(i,j+1)+ heat(i,j-1))/4
heat(i,j) = (relax)*heat(i,j) + (1-relax)*oldval
counter = counter + 1
maxError = maxval(error)
write(*,*) "The max error for this iteration of calculations is", maxError
end do
!writes total iterations, dummy count (calculations per iteration I beleive),
heat/solution matrix
write(*,*) "Iterations#:", counter
write(*,*) "dummy count", dummy
write(*,"(16f8.2)") heat
!Creates text file to store heat matrix values
open( unit = 1, file = 'heat.txt')
write(1,"(16f8.2)") heat
close(unit=1)
end pro