Program crank_nicolson
call thomas(a,b,c,d,JI)
Real, allocatable :: x),u),a),b),c),d)
Real:: m,dx,dt,Tmax
Integer:: j,NI,JI
Print*, 'Enter the total number of time steps'
read*, NI
Print*, 'Enter the final time'
read*, Tmax
dt=Tmax/NI !The size of timestep
Print*, 'This gives stepsize of time dt=',dt
dx= 0.1 !delta x =0.1
allocate (x(0:NI),u(0:JI),a(0:JI),b(0:JI),c(0:JI),d(0:JI))
m = dt/(2*dx**2)
JI= int(2/dx)-1
open(10,file='crank_nicolsan.m')
!Initial Condition
do j=1,JI-1
x(j)= -1+j*dx
u(j)=(1+x(j))*(1-x(j))**2 !x=-1+j*dx
end do
do n=1 ,NI-1 !BC
u=0 !b.c. at j=0
u(JI)=0 !b.c. at j=JI
do j = 1, JI
a(j) = -m
b(j) = 1+2*m
c(j) = -m
d(j) = m*u(j+1)+(1-2*m)*u(j)+m*u(j-1)
end do
end do
do j=1, JI-1
u(j)=d(j)
end do
!Print out the Approximate solution in matlab file
write(10,*) 'ApproximateSolution =[',x(0),u(0)
do j =1, JI
u(j) = initialfun(j,dx)
end do
write(10,*)x(JI),(JI),']'
end Program crank_nicolson
subroutine thomas (a,b,c,d,JI)
implicit none
real, intent(inout) :: a(*),b(*),c(*),d(*)
integer, intent(in) :: JI
integer j
do j = 2,JI !combined decomposition and forward substitution
a(j) = a(j)/b(j-1)
b(j) = b(j)-a(j)*c(j-1)
d(j) = d(j)-a(j)*d(j-1)
end do
!back substitution
d(j) = d(j)/b(j)
do j = JI-1,1,-1
d(j) = (d(j)-c(j)*d(j+1))/b(j)
end do
return
end subroutine thomas
Error: Statement ordering error - REAL cannot appear after executable statements in this line Real, allocatable :: x),u),a),b),c),d)
There might be some other errors and missing code too. Can help me and check my code please. Thanks in advance
call thomas(a,b,c,d,JI)
Real, allocatable :: x),u),a),b),c),d)
Real:: m,dx,dt,Tmax
Integer:: j,NI,JI
Print*, 'Enter the total number of time steps'
read*, NI
Print*, 'Enter the final time'
read*, Tmax
dt=Tmax/NI !The size of timestep
Print*, 'This gives stepsize of time dt=',dt
dx= 0.1 !delta x =0.1
allocate (x(0:NI),u(0:JI),a(0:JI),b(0:JI),c(0:JI),d(0:JI))
m = dt/(2*dx**2)
JI= int(2/dx)-1
open(10,file='crank_nicolsan.m')
!Initial Condition
do j=1,JI-1
x(j)= -1+j*dx
u(j)=(1+x(j))*(1-x(j))**2 !x=-1+j*dx
end do
do n=1 ,NI-1 !BC
u=0 !b.c. at j=0
u(JI)=0 !b.c. at j=JI
do j = 1, JI
a(j) = -m
b(j) = 1+2*m
c(j) = -m
d(j) = m*u(j+1)+(1-2*m)*u(j)+m*u(j-1)
end do
end do
do j=1, JI-1
u(j)=d(j)
end do
!Print out the Approximate solution in matlab file
write(10,*) 'ApproximateSolution =[',x(0),u(0)
do j =1, JI
u(j) = initialfun(j,dx)
end do
write(10,*)x(JI),(JI),']'
end Program crank_nicolson
subroutine thomas (a,b,c,d,JI)
implicit none
real, intent(inout) :: a(*),b(*),c(*),d(*)
integer, intent(in) :: JI
integer j
do j = 2,JI !combined decomposition and forward substitution
a(j) = a(j)/b(j-1)
b(j) = b(j)-a(j)*c(j-1)
d(j) = d(j)-a(j)*d(j-1)
end do
!back substitution
d(j) = d(j)/b(j)
do j = JI-1,1,-1
d(j) = (d(j)-c(j)*d(j+1))/b(j)
end do
return
end subroutine thomas
Error: Statement ordering error - REAL cannot appear after executable statements in this line Real, allocatable :: x),u),a),b),c),d)
There might be some other errors and missing code too. Can help me and check my code please. Thanks in advance