24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 990  |  回复: 3
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

physliebe

新虫 (小有名气)

[求助] 找不出毛病不知怎么改? 已有1人参与

计算系数矩阵为上三角的线性方程组Ax=b的解,N维
代码:
!##############################################
module tri_eq
contains
subroutine uptri(A,b,x,N)
implicit real*8(a-z) !a到z开头的变量都视为双精度浮点数
integer::i,j,k,N
real*8::A(N,N),b(N),x(N)
x(N)=b(N)/A(N,N)
!回代部分
do i=N-1,1,-1
do j=i+1,N
x(i)=b(i)-a(i,j)*x(j)
end do
x(i)=x(i)/A(i,i)
end do
end subroutine uptri
end module tri_eq
!############################################
module driver
contains
subroutine dri_main()
implicit real*8(a-z)
integer::ioerr !ioerr=0
character(20)::uptr
open(unit=11,file='fin.txt',iostat=ioerr)
open(unit=12,file='fout.txt')
do
read(11,*) uptr
!读输入文件
if(uptr(1:5)=='uptri') !提示这里有错误
call dri_up()
if(ioerr/=0) exit
end do
end subroutine dri_main
subroutine dri_up()
use tri_eq
implicit real*8(a-z)
integer,parameter::N=4
integer::i,j
real*8::A(N,N),b(N),x(N)
read(11,*)((A(i,j),j=1,N),i=1,N)
!读入b向量
read(11,*) b
call uptri(A,b,x,N)
write(12,101) x
101 format(T5,'上三角方程组的解',/,T4,'x='4(/f12.8))
end subroutine dri_up
end module driver
!################################################
program main
use driver
call dri_main()
end program main
!#################################################
其中fin.txt如下
uptri

      2  1  4  3
      0  3  2  5
      0  0  7  3
      0  0  0  2   

      50
      49
      53
      12
编译信息:
D:\fortran_programming\myfirst\main.f95:31.34:
          if(uptr(1:5)=='uptri')
                                           1
Error: Cannot assign to a named constant at (1)
D:\fortran_programming\myfirst\main.f95:51.8:
use driver
      1
Fatal Error: Can't open module file 'driver.mod' for reading 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))
回复此楼

» 猜你喜欢

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

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

新虫 (小有名气)

引用回帖:
2楼: Originally posted by btx97 at 2014-02-07 19:27:13
if(uptr(1:5)=='uptri') !提示这里有错误
call dri_up()


后面没有 END IF?

谢谢,是的。语法规定:if 如果不带 then 需要写成一行,如果写成两行,应该有 then 和 end if
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.
3楼2014-02-07 20:02:03
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 4 个回答

btx97

金虫 (小有名气)

【答案】应助回帖


感谢参与,应助指数 +1
physliebe: 金币+1, ★★★很有帮助 2014-02-07 20:01:04
if(uptr(1:5)=='uptri') !提示这里有错误
call dri_up()


后面没有 END IF?
2楼2014-02-07 19:27:13
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

btx97

金虫 (小有名气)

引用回帖:
3楼: Originally posted by physliebe at 2014-02-07 13:02:03
谢谢,是的。语法规定:if 如果不带 then 需要写成一行,如果写成两行,应该有 then 和 end if...

嗯。 if construct 和 if statement 的区别
4楼2014-02-07 20:40:04
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 0856求调剂 +7 楒桉 2026-03-28 7/350 2026-03-29 08:28 by fmesaito
[考研] 309求调剂 +6 谁不是少年 2026-03-29 6/300 2026-03-29 08:11 by fmesaito
[考研] 299求调剂 +8 15188958825 2026-03-25 8/400 2026-03-29 01:36 by fmesaito
[考研] 300求调剂,材料科学英一数二 +8 leaflight 2026-03-24 8/400 2026-03-29 01:31 by fmesaito
[考研] 283求调剂 +3 A child 2026-03-28 3/150 2026-03-28 15:41 by ms629
[考研] 320分,材料与化工专业,求调剂 +9 一定上岸aaa 2026-03-27 13/650 2026-03-28 15:00 by 神马都不懂
[考研] 0703一志愿9,初试成绩:338,四六级已过,有科研经历,求调剂! +4 Zuhui0306 2026-03-25 4/200 2026-03-28 13:07 by 唐沐儿
[考研] 材料求调剂一志愿哈工大324 +7 闫旭东 2026-03-28 9/450 2026-03-28 08:51 by Xu de nuo
[考博] 26申博 +3 加油冲啊! 2026-03-26 3/150 2026-03-27 15:38 by cls512
[考研] 305求调剂 +5 哇卢卡库 2026-03-26 5/250 2026-03-27 14:01 by laoshidan
[考研] 材料求调剂 +5 .m.. 2026-03-25 5/250 2026-03-27 11:08 by 不吃魚的貓
[论文投稿] Journal of Mechanical Science and Technology +3 Russ_ss 2026-03-25 5/250 2026-03-27 10:49 by 陆小果画大饼
[考研] 调剂 +4 柚柚yoyo 2026-03-26 4/200 2026-03-26 20:43 by fmesaito
[考研] 081200-11408-276学硕求调剂 +3 崔wj 2026-03-26 3/150 2026-03-26 19:57 by nihaoar
[考研] 总分322求生物学/生化与分子/生物信息学相关调剂 +5 星沉uu 2026-03-26 6/300 2026-03-26 19:02 by macy2011
[考研] 340求调剂 +3 Amber00 2026-03-26 3/150 2026-03-26 18:57 by 不吃魚的貓
[考研] 352求调剂 +4 大米饭! 2026-03-22 4/200 2026-03-26 16:40 by 不吃魚的貓
[考研] 化学调剂一志愿上海交通大学336分-本科上海211 +4 小鱼爱有机 2026-03-25 4/200 2026-03-26 10:19 by aa331100
[考研] 求调剂 +3 李李不服输 2026-03-25 3/150 2026-03-25 13:03 by cmz0325
[考研] 一志愿重庆大学085700资源与环境,总分308求调剂 +7 墨墨漠 2026-03-23 8/400 2026-03-23 20:36 by Creta
信息提示
请填处理意见