Hi, fellows.
I'm writing a scientific program for my thesis. But I have a little problem. I'm getting error message: severe <161>: Program Exception - array bounds exceeded for this line:
Here is the whole subprogram:
I already check that the variable n is properly readed form the data file.
I'm writing a scientific program for my thesis. But I have a little problem. I'm getting error message: severe <161>: Program Exception - array bounds exceeded for this line:
Code:
r(1) = alpha
Here is the whole subprogram:
Code:
subroutine Tridiagonal_Solv(n, a, b, alpha, beta, x, y, y_deriv, error)
implicit none
integer n, i
double precision h
double precision s(n), t(n)
double precision down(n), main(n), up(n)
double precision exact_sol(n + 2)
double precision r(n)
double precision x(n + 2)
double precision y(n), y_deriv(n)
double precision error
common /DIM/ D(1)
integer D
common /PAR/P(4)
double precision P
n = D(1)
a = P(1)
b = P(2)
alpha = P(3)
beta = P(4)
h = Step(n, a, b)
x(1) = a
r(1) = alpha
exact_sol(1) = ExactSolution(x(1))
error = r(1)**2
do i = 2, n - 1
x(i) = a + (i - 1)*h
r(i) = 2.0d0*dsin(x(i))
exact_sol(i) = ExactSolution(x(i))
error = error + r(i)**2
!print *, "r(", i, ") = ", r(i)
end do
r(n) = beta
error = error + r(n)**2
x(n) = b
exact_sol(n) = ExactSolution(x(n))
x(n + 1) = a + n*h
exact_sol(n + 1) = ExactSolution(x(n + 1))
x(n + 2) = a + (n + 1)*h
exact_sol(n + 2) = ExactSolution(x(n + 2))
do i = 1, n
y_deriv(i) = (-3.0d0*exact_sol(i) + 4.0d0*exact_sol(i + 1) - exact_sol(i + 2))/2.0d0*h
end do
do i = 2, n - 1
down(i) = -1.0d0/(h*h)
end do
down(n) = 2.0d0/h
main(1) = -3.0d0/(2.0d0*h)
do i = 2, n - 1
main(i) = (2.0d0/(h*h)) + 1.0d0
end do
main(n) = 3.0d0/(2.0d0*h)
up(1) = 2.0d0/h
do i = 2, n - 1
up(i) = -1.0d0/(h*h)
end do
s(1) = -(main(1)*up(2) - main(2)*up(1))/(down(1)*up(2) - down(2)*up(1))
t(1) = (up(2)*r(1) - up(1)*r(2))/(down(1)*up(2) - down(2)*up(1))
s(2) = -(up(1)*down(2) - up(2)*down(1))/(main(1)*down(2) - main(2)*down(1))
t(2) = (down(2)*r(1) - down(1)*r(2))/(main(1)*down(2) - main(2)*down(1))
do i = 3, n - 2
s(i) = -up(i)/(main(i) + down(i)*s(i - 1))
t(i) = (r(i) - down(i)*t(i - 1))/(main(i) + down(i)*s(i - 1))
end do
! Çàïèñâàìå ðåçóëòàòèòå îò ðåøåíèåòî íà ñèñòåìàòà âúâ âåêòîðà y
y(n) = ((r(n - 1) - t(n - 2)*down(n - 1))*(s(n - 2)*down(n) + main(n)) - (r(n) - t(n - 2)*down(n))*(s(n - 2)*down(n - 1) + main(n - 1)))/(up(n - 1)*(down(n)*s(n - 2) + main(n)) - up(n)*(down(n - 1)*s(n - 2) + main(n - 1)))
y(n - 1) = (r(n)*up(n - 1) - t(n - 2)*down(n)*up(n - 1) - r(n - 1)*up(n) + t(n - 2)*down(n - 1)*up(n))/(s(n - 2)*down(n)*up(n - 1) + main(n)*up(n - 1) - s(n - 2)*down(n - 1)*up(n) - main(n - 1)*up(n))
do i = n - 2, 3, -1
y(i) = s(i)*y(i + 1) + t(i)
end do
y(2) = s(2)*y(3) + t(2)
y(1) = s(1)*y(2) + t(1)
!print *
!do i = 1, n
! print *, "y(", i, ") = ", y(i)
!end do
end subroutine Tridiagonal_Solv
I already check that the variable n is properly readed form the data file.