0
これはニュートン・ラフソン法のFortran 90プログラムです。しかし、それは正しくコンパイルしgeanyあなただけの2つの警告を持って未使用の仮引数と関数の戻り値が設定されていません
newraph.f90:18.17:
real function f(x)
1
Warning: Unused dummy argument 'x' at (1)
newraph.f90:18.15:
real function f(x)
1
Warning: Return value of function 'f' at (1) not set
Compilation finished successfully.
program newton_raphson
implicit none
real,parameter::error=1e-4
integer::i
real::xo,x1,f,fd
read*,xo
i=1
10 x1=xo-(f(xo)/fd(xo))
if(abs((x1-xo)/x1)<error) then
print*,"root is", x1,"no. of iteration=",i
else
xo=x1
i=i+1
goto 10
endif
end
real function f(x)
real::x
end
real function fd(x)
real::x
fd=3*x**2-1
end
ノートブックからこのプログラムをコピーして実行したばかりなので、何か提案がありました。 –
[おそらく 'f'は' f = x ** 3-x + 27.6'のような結果を持つはずです。] – francescalus
@francescalus 'fd'が' f'の派生であるのは確かです。あるいは、 'fd'を' fd = 2 * x'に変更してください。 –