24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 999  |  回复: 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的回帖

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的回帖

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的回帖

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的回帖
相关版块跳转 我要订阅楼主 physliebe 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 材料求调剂 +11 一样YWY 2026-04-05 11/550 2026-04-05 23:36 by 来看流星雨10
[考研] 308求调剂 +3 终不似从前 2026-04-05 3/150 2026-04-05 22:23 by hemengdong
[考研] 270求调剂 +9 小杰pp 2026-03-31 11/550 2026-04-05 11:02 by 风雨无晴
[考研] 数一英一 347 人工智能国奖论文都有求调剂 +3 乌拉儿山脉 2026-03-30 7/350 2026-04-05 10:32 by zhq0425
[考研] 材料专硕322分 +11 哈哈哈吼吼吼哈 2026-04-02 11/550 2026-04-04 23:37 by 永字号
[考研] 283求调剂 +4 mcbbc 2026-04-03 5/250 2026-04-04 20:51 by imissbao
[考研] 338求调剂 +7 晟功? 2026-04-03 7/350 2026-04-04 20:37 by 蓝云思雨
[考研] 322求调剂 +4 FZAC123 2026-04-03 4/200 2026-04-03 20:55 by zhq0425
[考研] 286求调剂 +8 lim0922 2026-04-02 8/400 2026-04-03 20:19 by rzh123456
[考研] 求调剂 +4 15064154688 2026-04-03 5/250 2026-04-03 15:07 by zrongyan
[考研] 326分求调剂 +3 于是乎呢 2026-04-01 5/250 2026-04-03 14:23 by 于是乎呢
[硕博家园] 求老师收留 +9 lllq123 2026-04-03 9/450 2026-04-03 13:48 by 呼吸都是减肥
[考研] 求材料调剂 一志愿南昌大学 328分 +5 yyy..... 2026-04-03 5/250 2026-04-03 13:46 by 百灵童888
[考研] 08工科275分求调剂 +14 AaAa7420 2026-03-31 14/700 2026-04-03 11:13 by cocolv
[考研] 复试调剂 +3 bvzz 2026-04-01 3/150 2026-04-03 09:47 by 蓝云思雨
[考研] 285求调剂 +8 AZMK 2026-04-02 11/550 2026-04-02 20:16 by yulian1987
[考研] 生物与医药考研调剂 +5 铁憨憨123425 2026-03-31 5/250 2026-04-01 18:01 by syh9288
[考研] 339求调剂 +5 zjjkt 2026-03-31 5/250 2026-04-01 09:18 by JourneyLucky
[考研] 【调剂】一志愿厦大生物与医药调剂 +3 Echo虾米 2026-03-31 3/150 2026-04-01 08:40 by JourneyLucky
[考研] 求调剂 生物学 377分 +6 zzll03 2026-03-31 6/300 2026-03-31 17:33 by 唐沐儿
信息提示
请填处理意见