24小时热门版块排行榜    

查看: 1650  |  回复: 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 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 建议基金发布提前给出明确的时间点 +10 kulium 2026-08-21 12/600 2026-08-21 19:46 by kulium
[基金申请] 2026国自然函评费到账 +3 羊腰板 2026-08-21 3/150 2026-08-21 19:42 by kulium
[基金申请] 今日不放榜?网传国自然预计 8 月 27 日可查结果 +15 医学老男孩 2026-08-20 19/950 2026-08-21 18:54 by 医学老男孩
[基金申请] 看来今天不会放榜了? +8 chengyan1220 2026-08-21 11/550 2026-08-21 17:52 by dcqxinyang
[基金申请] filecode,4个jtjc了 +11 ziyangfang 2026-08-19 14/700 2026-08-21 16:51 by applepetty
[基金申请] 让我中一个面上吧! +11 大萍1987 2026-08-20 13/650 2026-08-21 14:48 by 20120902066
[基金申请] 感觉是下周放榜了 +7 angus9576 2026-08-17 12/600 2026-08-21 13:38 by weiyin
[基金申请] 我面上完蛋了 +7 且听虎啸 2026-08-20 8/400 2026-08-21 12:31 by 酷酷墨镜
[基金申请] 只有每年这种时候来逛逛小木虫 +23 yaoyewhu2008 2026-08-20 25/1250 2026-08-21 12:19 by Poppy1104
[基金申请] 今天放榜没戏了吧 +9 yuleib84 2026-08-19 11/550 2026-08-21 10:06 by gltch
[基金申请] 基金啊基金 +4 longfie172 2026-08-20 4/200 2026-08-21 08:58 by mark mao
[基金申请] 放榜前的不淡定 40+4 snowwithsea 2026-08-19 13/650 2026-08-21 08:30 by 北京莱茵编辑
[基金申请] 估计是周四 +3 archvillain 2026-08-18 3/150 2026-08-21 01:48 by jnhyjjm
[基金申请] 今天系统多次维护,明天很可能放榜! +10 zju2000 2026-08-16 11/550 2026-08-20 20:02 by cl479861084
[基金申请] 时间戳变了,能看出什么问题? +18 基诺咪客 2026-08-17 23/1150 2026-08-20 17:19 by Godzela
[基金申请] 重要消息,中午系统在维护 +11 yuleib84 2026-08-18 12/600 2026-08-20 11:09 by xskun
[教师之家] 为什么余额宝的年化利率越来越低?主要原因有哪些? +5 瞬息宇宙 2026-08-15 5/250 2026-08-19 20:23 by super2002521
[基金申请] 2027广东省杰青 +4 奶牛小黑 2026-08-15 10/500 2026-08-19 11:02 by wanfengnew
[基金申请] 朋友圈看到的 +6 wangzilk 2026-08-18 8/400 2026-08-19 10:55 by Haru815
[基金申请] 明天放榜? +5 Shxjjxjkx 2026-08-18 5/250 2026-08-18 18:14 by -大大大大大-
信息提示
请填处理意见