kyra 发表于 2017-10-25 11:18:51

dble 这个函数我从来不用。
转换成浮点数(不管精度是多少),都可以用 real 函数。

qp = real(i,8) 就可以了

shrine 发表于 2017-11-9 13:48:55

本帖最后由 shrine 于 2017-11-9 14:21 编辑

kyra 发表于 2017-10-25 11:18
dble 这个函数我从来不用。
转换成浮点数(不管精度是多少),都可以用 real 函数。


感谢一直以来的帮助
再请教一个语法问题,行向量和矩阵中的一列相乘难道不是一个数么
为何这段代码说c的形状不对呢
      
program main
      implicit none
      integer::a(2,2),b(1,2),c
      a(1,1)=1
      a(2,1)=2
      a(1,2)=5
      a(2,2)=6
      b(1,1)=3
      b(1,2)=4
      c=matmul(b,a(:,1))
      end

vvt 发表于 2017-11-9 15:06:20

向量,矩阵,是数学概念。
编程里只有一维数组,二维数组的概念。

通常我们用一维数组表示向量,二维数组表示矩阵。(但仅仅是表示,而非相等的概念)
其实 1*N 的二维数组,也可以表示向量。
matmul,必须对两个“二维数组”进行,并且结果也是二维数组(哪怕是1*1的二维数组呢)。显然,a(:,1) 是一维数组。(而 a(:,1:1)却是二维数组)

因此,你的选择可以是:
1. 改用 integer c(1,1) ; c = matmul( b , a(:,1:1) )
2. 改用 c = dot_product( b(1,:) , a(:,1) ) 此时是应用内积的算法

shrine 发表于 2017-11-9 15:35:45

vvt 发表于 2017-11-9 15:06
向量,矩阵,是数学概念。
编程里只有一维数组,二维数组的概念。



我还是老实点用dot_product吧,谢谢

pasuka 发表于 2017-11-9 15:40:41

本帖最后由 pasuka 于 2017-11-9 15:42 编辑

shrine 发表于 2017-11-9 13:48
感谢一直以来的帮助
再请教一个语法问题,行向量和矩阵中的一列相乘难道不是一个数么
为何这段代码说c的形 ...首先,翻阅gfortran帮助文档
https://gcc.gnu.org/onlinedocs/g ... /MATMUL.html#MATMUL
MATMUL — matrix multiplication
Description:
Performs a matrix multiplication on numeric or logical arguments.
Standard:
Fortran 95 and later
Class:
Transformational function
Syntax:
RESULT = MATMUL(MATRIX_A, MATRIX_B)
Arguments:
MATRIX_A      An array of INTEGER, REAL, COMPLEX, or LOGICAL type, with a rank of one or two.
MATRIX_B      An array of INTEGER, REAL, or COMPLEX type if MATRIX_A is of a numeric type; otherwise, an array of LOGICAL type. The rank shall be one or two, and the first (or only) dimension of MATRIX_B shall be equal to the last (or only) dimension of MATRIX_A.
Return value:
The matrix product of MATRIX_A and MATRIX_B. The type and kind of the result follow the usual type and kind promotion rules, as for the * or .AND. operators.

显然根据文档不难发现,输入和输出变量的rank都不会小于1,那么Fortran里面的rank又是怎么定义的呢?


接着查看rank函数
https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gfortran/RANK.html#RANK
The return value is of type INTEGER and of the default integer kind. For arrays, their rank is returned; for scalars zero is returned.

Example:
program test_rank
integer :: a
real, allocatable :: b(:,:)
print *, rank(a), rank(b) ! Prints:02
end program test_rank
页: 1 [2]
查看完整版本: 请问双双精度变量赋值时后缀加什么?