milkypros
Technical User
- Oct 25, 2009
- 11
The program i wrote below calculates the temparature distribution on a metal rod at 11 stations using Gauss-Seidel iterative method. How can i define in the program to stop the calculations when the temperatures T2 to T11 become: ?2,?3,?4,?5,?6,?7,?8,?9,?10=10,20,30,40,50,60,70,80,90
C __________________________________________________
C |__________________________________________________|
C T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11
C
C L=1 m
C T(x)=(100.x)/L
dimension T(11)
! Initial values for temperatures
data T/0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,100./
print *,'i T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11'
print 10,0,T
print*, Give number of max iterations n'
read*, n
do 20 i=1,n
T(1) = 0
T(2) = (T(1)+T(3))/2
T(3) = (T(2)+T(4))/2
T(4) = (T(3)+T(5))/2
T(5) = (T(4)+T(6))/2
T(6) = (T(5)+T(7))/2
T(7) = (T(6)+T(8))/2
T(8) = (T(7)+T(9))/2
T(9) = (T(8)+T(10))/2
T(10) = (T(9)+T(11))/2
T(11) = 100
print 10,i,T
20 continue
10 format (f7.3,1X,f7.3,1X,f7.3,1X,f7.3,1X,f7.3,1X,f7.3,1X,f7.3,1X,
& f7.3,1X,f7.3,1X,f7.3,1X,f7.3,1X)
stop
end
C __________________________________________________
C |__________________________________________________|
C T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11
C
C L=1 m
C T(x)=(100.x)/L
dimension T(11)
! Initial values for temperatures
data T/0.,1.,1.,1.,1.,1.,1.,1.,1.,1.,100./
print *,'i T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11'
print 10,0,T
print*, Give number of max iterations n'
read*, n
do 20 i=1,n
T(1) = 0
T(2) = (T(1)+T(3))/2
T(3) = (T(2)+T(4))/2
T(4) = (T(3)+T(5))/2
T(5) = (T(4)+T(6))/2
T(6) = (T(5)+T(7))/2
T(7) = (T(6)+T(8))/2
T(8) = (T(7)+T(9))/2
T(9) = (T(8)+T(10))/2
T(10) = (T(9)+T(11))/2
T(11) = 100
print 10,i,T
20 continue
10 format (f7.3,1X,f7.3,1X,f7.3,1X,f7.3,1X,f7.3,1X,f7.3,1X,f7.3,1X,
& f7.3,1X,f7.3,1X,f7.3,1X,f7.3,1X)
stop
end