Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fortran 在尝试交换行以形成精简的行梯队形式时发现问题_Fortran - Fatal编程技术网

Fortran 在尝试交换行以形成精简的行梯队形式时发现问题

Fortran 在尝试交换行以形成精简的行梯队形式时发现问题,fortran,Fortran,我写了一个代码,将一个方阵转换成它的简化行梯队形式。但是当需要行交换时,我遇到了一个问题。我认为我交换的方式给了我错误的输出。谁能帮我弄清楚这件事 是我的代码,你可以在那里运行。为了方便起见,我也把它放在这里 !there is a more direct way of entering the value of a matrix by row instead !as by column: reshape has an optional !argument ORDER which can be

我写了一个代码,将一个方阵转换成它的简化行梯队形式。但是当需要行交换时,我遇到了一个问题。我认为我交换的方式给了我错误的输出。谁能帮我弄清楚这件事

是我的代码,你可以在那里运行。为了方便起见,我也把它放在这里

!there is a more direct way of entering the value of a matrix by row instead !as by column: reshape has an optional 
!argument ORDER which can be used to modify the order of filling the element !of the multidimensional array with the entries of the array constructor.

PROGRAM RREF
IMPLICIT NONE
REAL,DIMENSION(3,3)::A=reshape((/0,0,1,1,2,3,0,1,-2/), shape(A), order=(/2,1/)),TEMP_FOR_SW(1,3)
INTEGER::ROW=3,COL=3,I,J,K,SW_PRINT
WRITE(*,100)TRANSPOSE(A)
100 FORMAT(3F6.2)
DO I=1,ROW
    IF(ABS(A(I,I))<1E-2)THEN
        WRITE(*,101)I
        101 FORMAT('SWAP NEEDED ROW=',I1)
        SW_PRINT=0
        DO K=1,col,1
            IF(A(K,I)>1E-2)THEN
                TEMP_FOR_SW=A(K:K,1:3)
                A(K:K,1:3)=A(I:I,1:3)
                A(I:I,1:3)=TEMP_FOR_SW
                IF(SW_PRINT<1)THEN
                    WRITE(*,102)K
                    102 FORMAT('SWAPPED WITH ROW=',I1)
                    SW_PRINT=SW_PRINT+1
                    END IF
                END IF
            END DO
        END IF
    A(I:I,1:3)=A(I:I,1:3)/(A(I,I))
    PRINT*,'--------------------------------------------------'
    WRITE(*,100)TRANSPOSE(A)
    DO J=1,COL
        IF(J /=  I)THEN
            A(J:J,1:3)=A(J:J,1:3)-(A(I:I,1:3)*A(J,I))
            PRINT*,'--------------------------------------------------'
            WRITE(*,100)TRANSPOSE(A)
            END IF
        END DO
    END DO
END PROGRAM RREF
根据Mathematica的说法。但我明白了:

 -0.14  0.00  0.00
  0.29  1.00  0.00
  0.14  0.00  1.00

编辑:我注意到问题是在行交换之后立即出现的

请标记所有Fortran问题。请在你的代码中使用一些注释,它几乎不可读,只是一堆文字。增加每个循环内的缩进级别,如果条件、ssubroutine和类似情况。@VladimirF Ok我将在几分钟内修复:)哪种方式输出错误?同时显示错误的输出。@VladimirF我为所有Fortran问题添加了同样的标记。请在你的代码中使用一些注释,它几乎不可读,只是一堆文字。增加每个循环内的缩进级别,如果条件、ssubroutine和类似情况。@VladimirF Ok我将在几分钟内修复:)哪种方式输出错误?同时显示错误的输出。@VladimirF我也添加了它
 -0.14  0.00  0.00
  0.29  1.00  0.00
  0.14  0.00  1.00