[問題] subroutine的問題
不好意思又來發問了
這個問題是用矩陣去解四元一次聯立方程式
程式可以跑了
但是我寫的subroutine backward(將矩陣右上方部分消掉)一直沒辦法運作
以下是主程式 跟subroutine
c Solving simultaneous equations
Program simul4
implicit none
integer maxdim, ndim, pivot_c, x
parameter(maxdim=100)
real*8 aug(maxdim, maxdim+1)
ndim=4
aug(1,1)=1; aug(1,2)=1; aug(1,3)=1; aug(1,4)=1; aug(1,5)=4
aug(2,1)=2; aug(2,2)=1; aug(2,3)=1; aug(2,4)=1; aug(2,5)=5
aug(3,1)=1; aug(3,2)=1; aug(3,3)=2; aug(3,4)=1; aug(3,5)=5
aug(4,1)=1; aug(4,2)=1; aug(4,3)=1; aug(4,4)=2; aug(4,5)=6
call displayMatrix(aug,ndim,ndim+1,maxdim,maxdim+1)
do pivot_c=1, ndim
call eliminatePivotColumn(aug,maxdim,maxdim+1,ndim,pivot_c)
call displayMatrix(aug,ndim,ndim+1,maxdim,maxdim+1)
end do
do x=1, ndim
call backward(aug,maxdim,maxdim+1,ndim,x)
call displayMatrix(aug,ndim,ndim+1,maxdim,maxdim+1)
end do
stop
End
c----------------------------------------------------------
subroutine backward(matrix, ndim, x ,m_max,n_max)
implicit none
integer col, pivot_r, i, j, m_max, n_max, ndim, x
real*8 matrix(m_max, n_max), tmp(n_max)
c backward
x=1
do i=x, ndim
do j=i+1, ndim+1
tmp(1)=matrix(i,j)
matrix(i,j)=matrix(i,j)-tmp(1)*matrix(i+1,j)
end do
end do
do i=x, ndim
do j=i+2, ndim+1
tmp(1)=matrix(i,j)
matrix(i,j)=matrix(i,j)-tmp(1)*matrix(i+2,j)
end do
end do
do i=x, ndim
do j=i+3,ndim+1
tmp(1)=matrix(i,j)
matrix(i,j)=matrix(i,j)-tmp(1)*matrix(i+3,j)
end do
end do
return
end
他display的矩陣是只有經過第一個subroutine 的eliminate的矩陣
第二個subroutine好像沒有運算到
為什麼會這樣?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.171.114.61
※ 編輯: joe1121111 來自: 118.171.114.61 (05/19 00:08)
→
05/19 00:16, , 1F
05/19 00:16, 1F
→
05/19 00:16, , 2F
05/19 00:16, 2F
→
05/19 15:41, , 3F
05/19 15:41, 3F
※ 編輯: joe1121111 來自: 118.171.114.61 (05/19 17:05)
→
05/19 22:44, , 4F
05/19 22:44, 4F
→
05/19 22:44, , 5F
05/19 22:44, 5F
※ 編輯: joe1121111 來自: 118.171.114.61 (05/19 23:21)
→
05/19 23:22, , 6F
05/19 23:22, 6F
→
05/19 23:22, , 7F
05/19 23:22, 7F
→
05/20 15:52, , 8F
05/20 15:52, 8F
→
05/20 15:53, , 9F
05/20 15:53, 9F
→
05/20 22:34, , 10F
05/20 22:34, 10F
Fortran 近期熱門文章
PTT數位生活區 即時熱門文章