用 Fortran 将复数矩阵写入文件
如何将 Fortran 中的复数 (n×n) 矩阵写入文件? 例如:
DO I=1,N
write(14,'(100g15.5)') ( M(i,j), j=1,n )
ENDDO
在此示例中,将 2n×n 个元素写入文件,即实数和虚数。 除了两个元素 Re(a11) Im(a11),我如何将其写为一个元素 Re(a11)+iIm(a11)?
How does one write a complex (n×n) matrix in Fortran to a file?
For example:
DO I=1,N
write(14,'(100g15.5)') ( M(i,j), j=1,n )
ENDDO
In this example one gets 2n×n elements written to the file i.e. the real and imaginary.
Instead of two element, Re(a11) Im(a11), How can I write it as one element Re(a11)+iIm(a11)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用内部函数 REAL 和 AIMAG 写入复数的各个实部和虚部:
说明:此代码定义一个字符串矩阵,当虚部为正时,其值为“+i”,当虚部为正时,值为“-i”消极的。因为负虚部在格式('-i')中被考虑,所以我们取虚部的绝对值。相应地编辑格式描述符,以便用于读取输出文件的程序能够读取它。
Use intrinsic functions REAL and AIMAG to write individual real and imaginary components of a complex number:
Explanation: This code defines a matrix of character strings that have value '+i' when imaginary part is positive, and '-i' where imaginary part is negative. Because the negative imaginary part is accounted for in the formatting ('-i'), we take absolute value of the imaginary part. Edit the format descriptor accordingly so that the program you use to read the output file will be able to read it.