dvbbs
收藏本页
联系我们
论坛帮助
dvbbs

>> Fortran语言使用经验交流
搜一搜更多此类问题 
Fortran中文网Fortran中文网—Fortran语言经验交流Fortran语言使用经验交流 → [求助]IMSL库函数中运算符号问题

您是本帖的第 3027 个阅读者
树形 打印
标题:
[求助]IMSL库函数中运算符号问题
linmue
帅哥哟,离线,有人找我吗?
等级:新手上路
文章:4
积分:256
门派:无门无派
注册:2006年10月19日
楼主
 用支付宝给linmue付款或购买其商品,支付宝交易免手续费、安全、快捷! 点击这里发送电子邮件给linmue

发贴心情
[求助]IMSL库函数中运算符号问题
不管高手低手都帮忙看一下:
program matrixmultiply
use IMSL
implicit none
  integer,parameter :: fileid=10
  character(len=80) :: filename = "data.txt"
  real :: A(3,3)=(/1,2,3,2,1,2,3,2,1/)
  real :: B(3,3)=(/1,-1,0,-1,0,1,1,1,0/)
  real :: C(3,3),AT(3,3),BT(3,3)
  real :: D(3,3),DT(3,3)
  AT=.t.A.x.B
  BT=.t.B.x.A
  DT=AT-BT
  c=.t.A.x.B-.t.B.x.A
  D=.t.A.x.B-(.t.B.x.A)
  open(fileid,file=filename)
  write(fileid,"('矩阵DT:',/,3(3XF7.3))")dt
  write(fileid,"('矩阵C:',/,3(3XF7.3))")c
  write(fileid,"('矩阵D:',/,3(3XF7.3))")d
  close(fileid)
  stop
end
我想得到A的转置乘以B减去B的转置乘以A的正确答案.
为什么只有按照分开的形式
AT=.t.A.x.B
BT=.t.B.x.A
DT=AT-BT    才正确呢?
而 C=.t.A.x.B-.t.B.x.A
D=.t.A.x.B-(.t.B.x.A)    却得不出正确答案呢?? 并且矩阵C和D得出的结果还不相同.
请各位解释一下.说说IMSL库函数中运算符号(如.x.,.ix.等)的使用规则
ip地址已设置保密
2006/10/22 21:29:15
linmue
帅哥哟,离线,有人找我吗?
等级:新手上路
文章:4
积分:256
门派:无门无派
注册:2006年10月19日
2
 用支付宝给linmue付款或购买其商品,支付宝交易免手续费、安全、快捷! 点击这里发送电子邮件给linmue

发贴心情

在编程爱好者论坛有人给我的回复是以下这样的:

嗯,使用者用这个Linear Algebra Operators的确是很容易出错的
其实帮助文件(IMSL5.0)第1466页在用图表介绍完这几个操作符后用深色的底强调了下面这段话:

A parsing rule in Fortran 90 states that the result of a defined operation involving two quantities has a lower precedence than any intrinsic operation. This explains the parentheses around the next-to-last line containing the sub-expression “A .x. y” found in the example. Users are advised to always include parentheses around array expressions that are mixed with defined operations, or whenever there is possible confusion without them.

大意是说虽然自定义了操作符的内容,但是操作符的优先级是由Fortran语法解析的规则决定的。涉及两个量的自定义操作的优先级总是低于内置操作的。所以编成者必须自行负责括号的添加。


也就是说,这样的操作等价:
  myx=.t.A.x.B - .t.B.x.A
  myy=.t.A.x.(B-.t.B).x.A

ip地址已设置保密
2006/10/23 12:58:10

 2   2   1/1页      1    
网上贸易 创造奇迹! 阿里巴巴 Alibaba
Powered By Dvbbs Version 7.1.0 Sp1
Copyright ©2005 - 2008 www.fortran.cn
页面执行时间 0.10156 秒, 5 次数据查询
京ICP备05056801号