当前位置:网站首页>FORTRAN77从文件中读入若干数据并用heron迭代公式开方
FORTRAN77从文件中读入若干数据并用heron迭代公式开方
2020-11-08 01:33:00 【wangxuwei】
要求做到:
1.不限制数据个数,自动计数并打印序号
2.遇到负数时,跳过开方,直接打印并标记
3.遇到0.0,程序停止
Heron迭代方法。
- 初始化 (X0 = A);(x1 =1/2*{x0+A/ x0});
- 计算 (Delta_k = |x1 - x0|;
- 若(Delta_k < epsilon),返回(x),算法结束;
- (x1 =1/2*{x0+A/ x0});
- 返回第2步;
C
C heronus1.f
C
C Unlimited number of data, automatic counting and printing serial number
C When negative numbers are encountered,skip square root, print them directly and mark them
C Encountered 0.0, the program stopped
PROGRAM heronus1
EPS=.1 E-4
I=0
OPEN(11,file='fheronus.dat')
10 READ(11,*)A
I=I+1
IF (A) 1,2,30
1 WRITE(6,100) I,A
100 FORMAT(1X, I6,10X,F10.6,' NEGATIVE NUMBER')
GO TO 10
2 STOP 'END OF JOB'
30 X0=A
20 X1=.5*(X0+A/X0)
IF (ABS(X1-X0).LT.EPS) GO TO 40
X0=X1
GO TO 20
40 WRITE(6,110) I,A,X1
110 FORMAT(1X, I6,2F10.6)
3 CONTINUE
GO TO 10
END
数据要以行来分割,而不是空格,并用0.0结束:
$ cat fheronus.dat
1
2
3
4
5
6
7
8
9
10
11
12
12
13
13
14
16
21
22
13
25
22
13
21
52
32
-23
121
12
0.0
运行:
$ f77 heronus1.f
$ a.out
1 1.000000 1.000000
2 2.000000 1.414214
3 3.000000 1.732051
4 4.000000 2.000000
5 5.000000 2.236068
6 6.000000 2.449490
7 7.000000 2.645751
8 8.000000 2.828427
9 9.000000 3.000000
10 10.000000 3.162278
11 11.000000 3.316625
12 12.000000 3.464102
13 12.000000 3.464102
14 13.000000 3.605551
15 13.000000 3.605551
16 14.000000 3.741657
17 16.000000 4.000000
18 21.000000 4.582576
19 22.000000 4.690416
20 13.000000 3.605551
21 25.000000 5.000000
22 22.000000 4.690416
23 13.000000 3.605551
24 21.000000 4.582576
25 52.000000 7.211102
26 32.000000 5.656854
27 -23.000000 NEGATIVE NUMBER
28121.000000 11.000000
29 12.000000 3.464102
STOP END OF JOB
ubutnu18.04下gfortran-10编译通过(vax780的f77也测试过)
版权声明
本文为[wangxuwei]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/2245781/blog/4707791
边栏推荐
- 14000 word distributed transaction principle analysis, master all of them, are you afraid of being asked in the interview?
- 你的主机中的软件中止了一个已建立的连接。解决方法
- Learn Scala if Else statement
- Web Security (4) -- XSS attack
- 微信昵称emoji表情,特殊表情导致列表不显示,导出EXCEL报错等问题解决!
- supervisor和Python多进程multiprocessing使用 子进程残留问题
- QT hybrid Python development technology: Python introduction, hybrid process and demo
- 来自不同行业领域的50多个对象检测数据集
- 【解决方案】分布式定时任务解决方案
- Web Security (3) -- CSRF attack
猜你喜欢
![[solution] distributed timing task solution](/img/3b/00bc81122d330c9d59909994e61027.jpg)
[solution] distributed timing task solution

1.深入Istio:Sidecar自动注入如何实现的?

0.计算机简史

Hand tearing algorithm - handwritten singleton mode

面部识别:攻击类型和反欺骗技术

什么你的电脑太渣?这几招包你搞定! (Win10优化教程)

Fortify漏洞之 Privacy Violation(隐私泄露)和 Null Dereference(空指针异常)

November 07, 2020: given an array of positive integers, the sum of two numbers equals N and must exist. How to find the two numbers with the smallest multiplication?

Wanxin Finance

LadonGo开源全平台渗透扫描器框架
随机推荐
Basic knowledge of C + +
Adobe media encoder /Me 2021软件安装包(附安装教程)
什么你的电脑太渣?这几招包你搞定! (Win10优化教程)
Python 图片识别 OCR
微信昵称emoji表情,特殊表情导致列表不显示,导出EXCEL报错等问题解决!
Insight -- the application of sanet in arbitrary style transfer
IDEA-项目未自动生成 .iml 文件
虚拟DOM中给同一层级的元素设置固定且唯一的key为什么能提高性能
On the stock trading of leetcode
Interface
Adobe Prelude / PL 2020 software installation package (with installation tutorial)
16.文件传输协议、vsftpd服务
The software in your host has terminated an established connection. resolvent
PerconaXtraDBCluster8.0 最详尽用法指南
Wechat nickname Emoji expression, special expression causes the list not to be displayed, export excel error report and other problems solved!
关于晋升全栈工程师,从入门到放弃的神功秘籍,不点进来看一看?
Lay UI left tree Dtree right list table
What? Your computer is too bad? You can handle these moves! (win10 optimization tutorial)
C++基础知识篇:C++ 基本语法
Mouse small hand