24小时热门版块排行榜    

CyRhmU.jpeg
查看: 1405  |  回复: 4

physliebe

新虫 (小有名气)

[求助] module无法编译?已有1人参与

用高斯消元法求解线性方程组
CODE:
module gauss
    contains
    subroutine solve(A,b,x,N)
        implicit real*8(a-z)
        integer::i,k,N
        real*8::A(N,N),b(N),x(N)
        real*8::Aup(N,N),bup(N)
        real*8::Ab(N,N+1)
        Ab(1:N,1:N)=A
        Ab(:,N+1)=b
        !+++++++++++++++++++++++++++++++++++++++++
        !高斯消去法的核心部分
        do k=1,N-1
            do i=k+1,N
                temp=Ab(i,k)/Ab(k,k)
                Ab(i,:)=Ab(i,:)-temp*Ab(k,:)
            end do
        end do
        Aup(:,:)=Ab(1:N,1:N)
        bup(:)=Ab(:,N+1)
        !+++++++++++++++++++++++++++++++++++++++++
        !求解上三角矩阵型的先性方程组
        call uptri(Aup,bup,x,N)   
        end subroutine solve
     subroutine uptri(A,b,x,N)        
        implicit real*8(a-z)         
        integer::i,j,N
        real*8::A(N,N),b(N),x(N)      
        x(N)=b(N)/A(N,N)              
        !回代部分
        do i=N-1,1,-1               
            x(i)=b(i)
            do j=i+1,N               
                x(i)=x(i)-a(i,j)*x(j)
            end do
            x(i)=x(i)/A(i,i)
        end do
    end subroutine uptri
end module gauss
program main
    use gauss
    implicit real*(a-z)
    integer,parameter::N=4
    integer::i,j
    real*8::A(N,N),b(N),x(N)
    open(unit=11,file='fin.txt')
    open(unit=12,file='fout.txt')
    read(11,*) ((A(i,j),j=1,N),i=1,N),b
    call solve(A,b,x,N)   !x在这里面的作用
    write(12,101) x
    101 format(T5,'高斯消去法计算结果',/,T4,4(f12.8))
end program main

错误信息:
end module gauss
                1
Fatal Error: Can't open module file 'D:\fortran_programming\gauss_1\main.os_output_dir/gauss.mod0' for writing at (1): No such file or directory
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))

[ Last edited by jjdg on 2014-2-9 at 10:01 ]
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

Whenever you feel like criticizing any one,just remember that all the people in this world haven’t had the advantages that you’ve had.
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

physliebe

新虫 (小有名气)

微笑表情处为冒号‘:’
Whenever you feel like criticizing any one,just remember that all the people in this world haven’t had the advantages that you’ve had.
2楼2014-02-08 20:56:04
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

snoopyzhao

至尊木虫 (职业作家)

【答案】应助回帖

★ ★ ★ ★ ★ ★
感谢参与,应助指数 +1
jjdg: 金币+1, 感谢参与 2014-02-09 10:02:02
physliebe: 金币+5 2014-02-09 12:21:04
至少用 gfortran 编译你贴出来的代码不止你上面提到的错误,但按照出错信息去修改又不会有什么问题

1)你在程序中使用中文的感叹号去注释代码是不行的
2)主程序中的隐式声明不全,所以代码是有问题的

消除了上面的两个问题好象就可以了

不赞成使用隐式声明,不赞成用 *8 这样的非标准写法……
3楼2014-02-09 05:22:20
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

physliebe

新虫 (小有名气)

引用回帖:
3楼: Originally posted by snoopyzhao at 2014-02-09 05:22:20
至少用 gfortran 编译你贴出来的代码不止你上面提到的错误,但按照出错信息去修改又不会有什么问题

1)你在程序中使用中文的感叹号去注释代码是不行的
2)主程序中的隐式声明不全,所以代码是有问题的

消除了 ...

谢谢,主要是我用了codeblocks13.12作为集成开发环境,没有配置好Toolchain excutables。标准写法是不是real,dimension(8)呢?
Whenever you feel like criticizing any one,just remember that all the people in this world haven’t had the advantages that you’ve had.
4楼2014-02-09 12:28:40
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

snoopyzhao

至尊木虫 (职业作家)

引用回帖:
4楼: Originally posted by physliebe at 2014-02-09 12:28:40
谢谢,主要是我用了codeblocks13.12作为集成开发环境,没有配置好Toolchain excutables。标准写法是不是real,dimension(8)呢?...

real*8 a 的标准写法是 real(kind=kind(1.0d0)) :: a或者更标准的写法是:
integer, parameter :: dp = SELECTED_REAL_KIND(15,307)
real(kind=dp) :: a
5楼2014-02-09 13:14:01
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 physliebe 的主题更新
信息提示
请填处理意见