回 帖 发 新 帖 刷新版面

主题:求一个解四元一次方程组的程序(自己写的不知道错在哪)

PROGRAM PDE_BV_Problem
IMPLICIT NONE


REAL(kind=8) A(1:1000,1:1000)
REAL(kind=8) B(1:1000)
REAL(kind=8) X(1:1000)
REAL(kind=8) det_A,det_AI
INTEGER I
!---
1 &
WRITE(*,*) "Please input the values of A(1,1),A(1,2),A(1,3),A(1,4)"
READ(*,*) A(1,1),A(1,2),A(1,3),A(1,4)
WRITE(*,*) "Please input the values of A(2,1),A(2,2),A(2,3),A(2,4)"
READ(*,*) A(2,1),A(2,2),A(2,3),A(2,4)
WRITE(*,*) "Please input the values of A(3,1),A(3,2),A(3,3),A(3,4)"
READ(*,*) A(3,1),A(3,2),A(3,3),A(4,4)
WRITE(*,*) "Please input the values of A(4,1),A(4,2),A(4,3),A(4,4)"
READ(*,*) A(4,1),A(4,2),A(4,3),A(4,4)
WRITE(*,*) "Please input the values of A(4,1),A(4,2),A(4,3),A(4,4)"
READ(*,*) A(4,1),A(4,2),A(4,3),A(4,4)
WRITE(*,*) "Please input the values of B(1),B(2),B(3),B(4)"
READ(*,*) B(1),B(2),B(3),B(4)
!---
det_A=(A(1,1)*A(2,2)*A(3,3)*A(4,4)+A(1,2)*A(2,3)*A(3,4)*A(4,1)+A(1,3)*A(2,4)*A(3,1)*A(4,2)+A(1,4)*A(2,1)*A(3,2)*A(4,3))-(A(1,1)*A(2,4)*A(3,3)*A(4,2)+A(1,2)*A(2,1)*A(3,4)*A(4,3)+A(1,3)*A(2,2)*A(3,1)*A(4,4)+A(1,4)*A(2,3)*A(3,2)*A(4,1))
DO I=1,4,1

  IF (I .EQ. 1) THEN
det_AI=(B(1)*A(2,2)*A(3,3)*A(4,4)+A(1,2)*A(2,3)*A(3,4)*B(4)+A(1,3)*A(2,4)*B(3)*A(4,2)+A(1,4)*B(2)*A(3,2)*A(4,3))-(B(1)*A(2,4)*A(3,3)*A(4,2)+A(1,2)*B(2)*A(3,4)*A(4,3)+A(1,3)*A(2,2)*B(3)*A(4,4)+A(1,4)*A(2,3)*A(3,2)*B(4))

  ELSE IF (I .EQ. 2) THEN
det_AI=(A(1,1)*B(2)*A(3,3)*A(4,4)+B(1)*A(2,3)*A(3,4)*A(4,1)+A(1,3)*A(2,4)*A(3,1)*B(4)+A(1,4)*A(2,1)*B(3)*A(4,3))-(A(1,1)*A(2,4)*A(3,3)*B(4)+B(1)*A(2,1)*A(3,4)*A(4,3)+A(1,3)*B(2)*A(3,1)*A(4,4)+A(1,4)*A(2,3)*B(3)*A(4,1))

  ELSE IF (I .EQ. 3) THEN
det_AI=(A(1,1)*A(2,2)*B(3)*A(4,4)+A(1,2)*B(2)*A(3,4)*A(4,1)+B(1)*A(2,4)*A(3,1)*A(4,2)+A(1,4)*A(2,1)*A(3,2)*B(4))-(A(1,1)*A(2,4)*B(3)*A(4,2)+A(1,2)*A(2,1)*A(3,4)*B(4)+B(1)*A(2,2)*A(3,1)*A(4,4)+A(1,4)*B(2)*A(3,2)*A(4,1))

  ELSE IF (I .EQ. 4) THEN
det_AI=(A(1,1)*A(2,2)*A(3,3)*B(4)+A(1,2)*A(2,3)*B(3)*A(4,1)+A(1,3)*B(2)*A(3,1)*A(4,2)+B(1)*A(2,1)*A(3,2)*A(4,3))-(A(1,1)*B(2)*A(3,3)*A(4,2)+A(1,2)*A(2,1)*B(3)*A(4,3)+A(1,3)*A(2,2)*A(3,1)*B(4)+B(1)*A(2,3)*A(3,2)*A(4,1))
  END IF
  X(I)=det_AI/det_A
  WRITE(*,fmt="(A6,I1,A2,F10.4)")"X(",")=",X(I)
END DO
GOTO 1

END PROGRAM PDE_BV_Problem



可以运行 可是一敲数据进去就自动跳没了  - -

求指导。T.T

回复列表 (共3个回复)

沙发

REAL(kind=8) A(1:1000,1:1000)
REAL(kind=8) B(1:1000)
REAL(kind=8) X(1:1000)
问题就在这儿,您就一个四元方程,这么浪费内存做啥?

板凳

cgl_lgs 前辈,好久都没来论坛了,想您请教个问题,学fortran有什么比较好的入门书籍么?

3 楼

如果不知道数组大小,那就用动态数组吧。在声明的时候用allocatable,在使用的时候用allocate。

我来回复

您尚未登录,请登录后再回复。点此登录或注册