一般数学関数#
acos#
名前#
acos(3) - [数学:三角関数] 逆余弦関数
概要#
result = acos(x)
elemental TYPE(kind=KIND) function acos(x)
TYPE(kind=KIND),intent(in) :: x
特性#
TYPE は 実数型 または 複素数型 です。
KIND は、関連付けられた型でサポートされている任意の種別です。
戻り値は、引数と同じ型と種別になります。
説明#
acos(3) は、x の逆余弦 (cos(x) の逆関数) を計算します。
オプション#
- x
逆余弦を計算する値。
型が 実数型 の場合、値は |x| <= 1 を満たす必要があります。
結果#
戻り値は x と同じ型と種別です。結果の実数部はラジアン単位で、0 <= acos(x%re) <= PI の範囲にあります。
例#
サンプルプログラム
program demo_acos
use, intrinsic :: iso_fortran_env, only : real_kinds,real32,real64,real128
implicit none
character(len=*),parameter :: all='(*(g0,1x))'
real(kind=real64) :: x , d2r
! basics
x = 0.866_real64
print all,'acos(',x,') is ', acos(x)
! acos(-1) should be PI
print all,'for reference &
&PI ~= 3.14159265358979323846264338327950288419716939937510'
write(*,*) acos(-1.0_real64)
d2r=acos(-1.0_real64)/180.0_real64
print all,'90 degrees is ', d2r*90.0_real64, ' radians'
! elemental
print all,'elemental',acos([-1.0,-0.5,0.0,0.50,1.0])
! complex
print *,'complex',acos( (-1.0, 0.0) )
print *,'complex',acos( (-1.0, -1.0) )
print *,'complex',acos( ( 0.0, -0.0) )
print *,'complex',acos( ( 1.0, 0.0) )
end program demo_acos
結果
acos( 0.86599999999999999 ) is 0.52364958093182890
for reference PI ~= 3.14159265358979323846264338327950288419716939937510
3.1415926535897931
90 degrees is 1.5707963267948966 radians
elemental 3.14159274 2.09439516 1.57079637 1.04719758 0.00000000
complex (3.14159274,-0.00000000)
complex (2.23703575,1.06127501)
complex (1.57079637,0.00000000)
complex (0.00000000,-0.00000000)
標準#
FORTRAN 77; 複素数 引数の場合 - Fortran 2008
参照#
逆関数: cos(3)
リソース#
fortran-lang intrinsic descriptions (license: MIT) @urbanjost
acosh#
名前#
acosh(3) - [数学:三角関数] 逆双曲線余弦関数
概要#
result = acosh(x)
elemental TYPE(kind=KIND) function acosh(x)
TYPE(kind=KIND),intent(in) :: x
特性#
TYPE は 実数型 または 複素数型 です。
KIND は、関連付けられた型でサポートされている任意の種別です。
戻り値は、引数と同じ型と種別になります。
説明#
acosh(3) は、x の逆双曲線余弦をラジアン単位で計算します。
オプション#
- x
双曲線余弦を計算する値
結果#
結果は、X の逆双曲線余弦関数のプロセッサ依存の近似値です。
x が 複素数 の場合、結果の虚数部はラジアン単位で、
0 <= aimag(acosh(x)) <= PI
の間にあります。
サンプルプログラム
program demo_acosh
use,intrinsic :: iso_fortran_env, only : dp=>real64,sp=>real32
implicit none
real(kind=dp), dimension(3) :: x = [ 1.0d0, 2.0d0, 3.0d0 ]
write (*,*) acosh(x)
end program demo_acosh
結果
0.000000000000000E+000 1.31695789692482 1.76274717403909
例#
標準#
Fortran 2008
参照#
逆関数: cosh(3)
fortran-lang intrinsic descriptions (license: MIT) @urbanjost
Wikipedia:双曲線関数
asin#
名前#
asin(3) - [数学:三角関数] 逆正弦関数
result = asin(x)
elemental TYPE(kind=KIND) function asin(x)
TYPE(kind=KIND) :: x
概要#
TYPE は 実数型 または 複素数型 です。
KIND は、関連付けられた型でサポートされている任意の種別です。
戻り値は、引数と同じ型と種別になります。
特性#
説明#
asin(3) は、引数 x の逆正弦を計算します。
逆正弦は、正弦関数の逆関数です。直角三角形の斜辺と対辺の長さがわかっているときに角度を求めようとする場合、三角法でよく使用されます。
- x
オプション#
逆正弦を計算する値
型は、実数型 で、大きさが1以下の値であるか、複素数型 である必要があります。
結果#
結果 結果の値は、arcsin(x) のプロセッサ依存の近似値です。
PI/2 <= ASIN (X) <= PI/2.
x が実数の場合は結果は *実数* であり、ラジアン単位で表され、
-PI/2 <= real(asin(x)) <= PI/2
の範囲にあります. 引数 (したがって結果) が虚数の場合、結果の実数部はラジアン単位で、
の範囲にあります
例#
sin(theta) = 1.25 miles/50 miles (opposite/hypotenuse)
サンプルプログラム
program demo_asin
use, intrinsic :: iso_fortran_env, only : dp=>real64
implicit none
! value to convert degrees to radians
real(kind=dp),parameter :: D2R=acos(-1.0_dp)/180.0_dp
real(kind=dp) :: angle, rise, run
character(len=*),parameter :: all='(*(g0,1x))'
! given sine(theta) = 1.25 miles/50 miles (opposite/hypotenuse)
! then taking the arcsine of both sides of the equality yields
! theta = arcsine(1.25 miles/50 miles) ie. arcsine(opposite/hypotenuse)
rise=1.250_dp
run=50.00_dp
angle = asin(rise/run)
print all, 'angle of incline(radians) = ', angle
angle = angle/D2R
print all, 'angle of incline(degrees) = ', angle
print all, 'percent grade=',rise/run*100.0_dp
end program demo_asin
結果
angle of incline(radians) = 2.5002604899361139E-002
angle of incline(degrees) = 1.4325437375665075
percent grade= 2.5000000000000000
逆正弦を使用すると、角度の対辺と斜辺の比率がわかっている場合に、直角の大きさを求めることができます。
たとえば、線路が50マイルの長さで、垂直方向に1.25マイル上昇していることがわかっている場合、逆正弦を使用して線路の平均傾斜角度を求めることができます。以下のようにします。
パーセント勾配とは、パーセントで表した勾配です。勾配を計算するには、上昇を水平距離で割ります。この例では、上昇は1.25マイルで、水平距離は50マイルなので、勾配は1.25/50 = 0.025です。パーセントで表すと、2.5%です。
米国では、2.5%が一般的に上限と考えられています。これは、100フィート前進するごとに2.5フィート上昇することを意味します。米国では、これは最初の主要な米国鉄道であるボルチモア・アンド・オハイオ鉄道の最大勾配でした。カーブは列車の摩擦抵抗を増大させるため、許容勾配が減少することに注意してください。
標準#
FORTRAN 77、*複素数* 引数の場合 Fortran 2008
参照#
fortran-lang intrinsic descriptions (license: MIT) @urbanjost
逆関数: sin(3)
リソース#
asinh#
名前#
result = asinh(x)
elemental TYPE(kind=KIND) function asinh(x)
TYPE(kind=KIND) :: x
asinh(3) - [数学:三角関数] 逆双曲線正弦関数
KIND は、関連付けられた型でサポートされている任意の種別です。
戻り値は、引数 **x** と同じ型と種別になります。
説明#
- x
asinh(3) は、**x** の逆双曲線正弦を計算します。
オプション#
逆双曲線正弦を計算する値
結果#
結果は、**x** の逆双曲線正弦関数のプロセッサ依存の近似値です。
サンプルプログラム
program demo_asinh
use,intrinsic :: iso_fortran_env, only : dp=>real64,sp=>real32
implicit none
real(kind=dp), dimension(3) :: x = [ -1.0d0, 0.0d0, 1.0d0 ]
! elemental
write (*,*) asinh(x)
end program demo_asinh
結果
-0.88137358701954305 0.0000000000000000 0.88137358701954305
**x** が *複素数* の場合、結果の虚数部はラジアン単位で、 **-PI/2 <= aimag(asinh(x)) <= PI/2** の間にあります。
標準#
例#
逆関数: sinh(3)
リソース#
fortran-lang intrinsic descriptions (license: MIT) @urbanjost
atan#
名前#
atan(3) - [数学:三角関数] 逆正接関数(アークタンジェント)
概要#
result = atan([x) | atan(y, x)
elemental TYPE(kind=KIND) function atan(y,x)
TYPE(kind=KIND),intent(in) :: x
TYPE(kind=**),intent(in),optional :: y
特性#
y が存在する場合、x と y は両方とも *実数* でなければなりません。そうでない場合、x は *複素数* でもかまいません。
KIND は、関連付けられた型でサポートされている任意の種類にすることができます。
戻り値は、x と同じ型と種類になります。
説明#
atan(3) は、x の逆正接を計算します。
オプション#
- x
逆正接を計算する値。y が存在する場合、x は *実数* でなければなりません。
- y
は x と同じ型と種類です。x がゼロの場合、y はゼロであってはなりません。
結果#
戻り値は、x と同じ型と種類になります。y が存在する場合、結果は atan2(y,x) と同じです。そうでない場合、結果は x の逆正接であり、結果の実数部はラジアン単位で、-PI/2 <= atan(x) <= PI/2 の範囲にあります。
例#
サンプルプログラム
program demo_atan
use, intrinsic :: iso_fortran_env, only : real_kinds, &
& real32, real64, real128
implicit none
character(len=*),parameter :: all='(*(g0,1x))'
real(kind=real64),parameter :: &
Deg_Per_Rad = 57.2957795130823208767981548_real64
real(kind=real64) :: x
x=2.866_real64
print all, atan(x)
print all, atan( 2.0d0, 2.0d0),atan( 2.0d0, 2.0d0)*Deg_Per_Rad
print all, atan( 2.0d0,-2.0d0),atan( 2.0d0,-2.0d0)*Deg_Per_Rad
print all, atan(-2.0d0, 2.0d0),atan(-2.0d0, 2.0d0)*Deg_Per_Rad
print all, atan(-2.0d0,-2.0d0),atan(-2.0d0,-2.0d0)*Deg_Per_Rad
end program demo_atan
結果
1.235085437457879
.7853981633974483 45.00000000000000
2.356194490192345 135.0000000000000
-.7853981633974483 -45.00000000000000
-2.356194490192345 -135.0000000000000
標準#
複素数引数の場合:FORTRAN 77、2つの引数の場合:Fortran 2008
関連項目#
リソース#
fortran-lang intrinsic descriptions (license: MIT) @urbanjost
atan2#
名前#
atan2(3) - [数学:三角関数] 逆正接関数(アークタンジェント)
概要#
result = atan2(y, x)
elemental real(kind=KIND) function atan2(y, x)
real,kind=KIND) :: atan2
real,kind=KIND),intent(in) :: y, x
特性#
x と y は同じ種類の *実数* でなければなりません。
戻り値は、y および x と同じ型と種類を持ちます。
説明#
atan2(3) は、複素数 (x, y) の逆正接、または値 y/x の逆正接の主値(一意の角度を決定する)を、プロセッサに依存する近似値でラジアン単位で計算します。
y の値がゼロの場合、x の値はゼロであってはなりません。
結果の位相は -PI <= ATAN2 (Y,X) <= PI の範囲にあり、arctan(Y/X) の値のプロセッサに依存する近似値と等しくなります。
オプション#
- y
複素数値 **(x,y)** の虚数部、または点 **<x,y>** の **y** 成分。
- x
複素数値 **(x,y)** の実数部、または点 **<x,y>** の **x** 成分。
結果#
戻り値は、定義により複素数 **(x, y)** の主値、言い換えればフェーザ x+i*y の位相です。
主値とは、ラジアン値を **-PI** から **PI** までの範囲(両端を含む)に調整したときに得られる値です。
逆正接の古典的な定義は、原点 **<0,0>** から点 **<x,y>** への直線がデカルト座標で形成する角度です。
ベクトルとして描くと、**x** と **y** が両方ともゼロの場合、角度は原点の真上に位置するため不定となります。そのため、**atan(0.0,0.0)** はエラーを生成します。
象限ごとの戻り値の範囲
> +PI/2
> |
> |
> PI/2 < z < PI | 0 > z < PI/2
> |
> +-PI -------------+---------------- +-0
> |
> PI/2 < -z < PI | 0 < -z < PI/2
> |
> |
> -PI/2
>
NOTES:
If the processor distinguishes -0 and +0 then the sign of the
returned value is that of Y when Y is zero, else when Y is zero
the returned value is always positive.
例#
サンプルプログラム
program demo_atan2
real :: z
complex :: c
!
! basic usage
! ATAN2 (1.5574077, 1.0) has the value 1.0 (approximately).
z=atan2(1.5574077, 1.0)
write(*,*) 'radians=',z,'degrees=',r2d(z)
!
! elemental arrays
write(*,*)'elemental',atan2( [10.0, 20.0], [30.0,40.0] )
!
! elemental arrays and scalars
write(*,*)'elemental',atan2( [10.0, 20.0], 50.0 )
!
! break complex values into real and imaginary components
! (note TAN2() can take a complex type value )
c=(0.0,1.0)
write(*,*)'complex',c,atan2( x=c%re, y=c%im )
!
! extended sample converting cartesian coordinates to polar
COMPLEX_VALS: block
real :: ang, radius
complex,allocatable :: vals(:)
!
vals=[ &
( 1.0, 0.0 ), & ! 0
( 1.0, 1.0 ), & ! 45
( 0.0, 1.0 ), & ! 90
(-1.0, 1.0 ), & ! 135
(-1.0, 0.0 ), & ! 180
(-1.0,-1.0 ), & ! 225
( 0.0,-1.0 )] ! 270
do i=1,size(vals)
call cartesian_to_polar(vals(i)%re, vals(i)%im, radius,ang)
write(*,101)vals(i),ang,r2d(ang),radius
enddo
101 format( &
& 'X= ',f5.2, &
& ' Y= ',f5.2, &
& ' ANGLE= ',g0, &
& T38,'DEGREES= ',g0.4, &
& T54,'DISTANCE=',g0)
endblock COMPLEX_VALS
!
contains
!
elemental real function r2d(radians)
! input radians to convert to degrees
doubleprecision,parameter :: DEGREE=0.017453292519943d0 ! radians
real,intent(in) :: radians
r2d=radians / DEGREE ! do the conversion
end function r2d
!
subroutine cartesian_to_polar(x,y,radius,inclination)
! return angle in radians in range 0 to 2*PI
implicit none
real,intent(in) :: x,y
real,intent(out) :: radius,inclination
radius=sqrt(x**2+y**2)
if(radius.eq.0)then
inclination=0.0
else
inclination=atan2(y,x)
if(inclination < 0.0)inclination=inclination+2*atan2(0.0d0,-1.0d0)
endif
end subroutine cartesian_to_polar
!
end program demo_atan2
結果
> radians= 1.000000 degrees= 57.29578
> elemental 0.3217506 0.4636476
> elemental 0.1973956 0.3805064
> complex (0.0000000E+00,1.000000) 1.570796
> X= 1.00 Y= 0.00 ANGLE= .000000 DEGREES= .000 DISTANCE=1.000000
> X= 1.00 Y= 1.00 ANGLE= .7853982 DEGREES= 45.00 DISTANCE=1.414214
> X= 0.00 Y= 1.00 ANGLE= 1.570796 DEGREES= 90.00 DISTANCE=1.000000
> X= -1.00 Y= 1.00 ANGLE= 2.356194 DEGREES= 135.0 DISTANCE=1.414214
> X= -1.00 Y= 0.00 ANGLE= 3.141593 DEGREES= 180.0 DISTANCE=1.000000
> X= -1.00 Y= -1.00 ANGLE= 3.926991 DEGREES= 225.0 DISTANCE=1.414214
> X= 0.00 Y= -1.00 ANGLE= 4.712389 DEGREES= 270.0 DISTANCE=1.000000
標準#
FORTRAN 77
関連項目#
リソース#
arctan:wikipedia _fortran-lang intrinsic descriptions (license: MIT) @urbanjost_
atanh#
名前#
atanh(3) - [数学:三角関数] 逆双曲線正接関数
概要#
result = atanh(x)
elemental TYPE(kind=KIND) function atanh(x)
TYPE(kind=KIND),intent(in) :: x
特性#
x は、任意の関連タイプの *実数* または *複素数* です。
戻り値は、引数と同じ型と種別になります。
説明#
atanh(3) は x の逆双曲線正接を計算します。
オプション#
- x
型は *実数* または *複素数* でなければなりません。
結果#
戻り値は、x と同じ型と種類を持ちます。x が *複素数* の場合、結果の虚数部はラジアン単位で、以下の範囲にあります。
**-PI/2 <= aimag(atanh(x)) <= PI/2**
例#
サンプルプログラム
program demo_atanh
implicit none
real, dimension(3) :: x = [ -1.0, 0.0, 1.0 ]
write (*,*) atanh(x)
end program demo_atanh
結果
> -Infinity 0.0000000E+00 Infinity
標準#
標準#
関連項目#
逆関数:tanh(3)
リソース#
fortran-lang intrinsic descriptions (license: MIT) @urbanjost
cos#
名前#
cos(3) - [数学:三角関数] 余弦関数
概要#
result = cos(x)
elemental TYPE(kind=KIND) function cos(x)
TYPE(kind=KIND),intent(in) :: x
特性#
x は、任意の有効な種類の *実数* または *複素数* です。
KIND は、x の関連付けられた型でサポートされている任意の種類にすることができます。
戻り値は、引数 **x** と同じ型と種類になります。
説明#
cos(3) は、ラジアン単位で指定された角度 **x** の余弦を計算します。
*実数* 値の余弦は、直角三角形において隣辺と斜辺の比です。
オプション#
- x
余弦を計算する角度(ラジアン単位)。
結果#
戻り値は **x** の正接です。
x が *実数* 型の場合、戻り値はラジアン単位で、**-1 <= cos(x) <= 1** の範囲にあります。
x が複素数型の場合、その実数部はラジアン単位の値と見なされ、しばしば位相と呼ばれます。
例#
サンプルプログラム
program demo_cos
implicit none
character(len=*),parameter :: g2='(a,t20,g0)'
doubleprecision,parameter :: PI=atan(1.0d0)*4.0d0
write(*,g2)'COS(0.0)=',cos(0.0)
write(*,g2)'COS(PI)=',cos(PI)
write(*,g2)'COS(PI/2.0d0)=',cos(PI/2.0d0),'EPSILON=',epsilon(PI)
write(*,g2)'COS(2*PI)=',cos(2*PI)
write(*,g2)'COS(-2*PI)=',cos(-2*PI)
write(*,g2)'COS(-2000*PI)=',cos(-2000*PI)
write(*,g2)'COS(3000*PI)=',cos(3000*PI)
end program demo_cos
結果
> COS(0.0)= 1.000000
> COS(PI)= -1.000000000000000
> COS(PI/2.0d0)= .6123233995736766E-16
> EPSILON= .2220446049250313E-15
> COS(2*PI)= 1.000000000000000
> COS(-2*PI)= 1.000000000000000
> COS(-2000*PI)= 1.000000000000000
> COS(3000*PI)= 1.000000000000000
標準#
FORTRAN 77
関連項目#
リソース#
fortran-lang intrinsic descriptions
cosh#
名前#
cosh(3) - [数学:三角関数] 双曲線余弦関数
概要#
result = cosh(x)
elemental TYPE(kind=KIND) function cosh(x)
TYPE(kind=KIND),intent(in) :: x
特性#
TYPE は、任意の *実数* または *複素数* です。
戻り値は、引数と同じ型と種別になります。
説明#
cosh(3) は **x** の双曲線余弦を計算します。
x が複素数型の場合、その虚数部はラジアン単位の値と見なされます。
オプション#
- x
双曲線余弦を計算する値
結果#
x が *複素数* の場合、結果の虚数部はラジアン単位です。
x が *実数* の場合、戻り値の下限は 1 です。**cosh(x) >= 1**。
例#
サンプルプログラム
program demo_cosh
use, intrinsic :: iso_fortran_env, only : &
& real_kinds, real32, real64, real128
implicit none
real(kind=real64) :: x = 1.0_real64
write(*,*)'X=',x,'COSH(X=)',cosh(x)
end program demo_cosh
結果
> X= 1.00000000000000 COSH(X=) 1.54308063481524
標準#
複素数引数の場合:FORTRAN 77、Fortran 2008
関連項目#
逆関数:acosh(3)
リソース#
fortran-lang intrinsic descriptions
sin#
名前#
sin(3) - [数学:三角関数] 正弦関数
概要#
result = sin(x)
elemental TYPE(kind=KIND) function sin(x)
TYPE(kind=KIND) :: x
特性#
概要#
KIND は、x の関連付けられた型でサポートされている任意の種類にすることができます。
戻り値は、引数 **x** と同じ型と種類になります。
説明#
sin(3) は、ラジアン単位で指定された角度の正弦を計算します。
直角三角形における角度の正弦は、指定された角度の対辺の長さを斜辺の長さで割った比率です。
オプション#
- x
正弦を計算する角度(ラジアン単位)。
結果#
result 戻り値には、**x** の正弦のプロセッサに依存する近似値が含まれます。
X が *実数* 型の場合、ラジアン単位の値と見なされます。
X が *複素数* 型の場合、その実数部はラジアン単位の値と見なされます。
例#
サンプルプログラム
program sample_sin
implicit none
real :: x = 0.0
x = sin(x)
write(*,*)'X=',x
end program sample_sin
結果
> X= 0.0000000E+00
拡張例#
ハバーサイン公式#
Wikipedia の「ハバーサイン公式」の記事より
The haversine formula is an equation important in navigation,
giving great-circle distances between two points on a sphere from
their longitudes and latitudes.
米国テネシー州のナッシュビル国際空港 (BNA) と米国カリフォルニア州のロサンゼルス国際空港 (LAX) の大円距離を示すには、一般的に次のように表される緯度と経度から始めます。
BNA: N 36 degrees 7.2', W 86 degrees 40.2'
LAX: N 33 degrees 56.4', W 118 degrees 24.0'
これは、度単位の浮動小数点値に変換すると次のようになります。
Latitude Longitude
- BNA
36.12, -86.67
- LAX
33.94, -118.40
そして、ハバーサイン公式を使用して、2 つの地点間の地球の表面に沿った距離を大まかに計算します。
サンプルプログラム
program demo_sin
implicit none
real :: d
d = haversine(36.12,-86.67, 33.94,-118.40) ! BNA to LAX
print '(A,F9.4,A)', 'distance: ',d,' km'
contains
function haversine(latA,lonA,latB,lonB) result (dist)
!
! calculate great circle distance in kilometers
! given latitude and longitude in degrees
!
real,intent(in) :: latA,lonA,latB,lonB
real :: a,c,dist,delta_lat,delta_lon,lat1,lat2
real,parameter :: radius = 6371 ! mean earth radius in kilometers,
! recommended by the International Union of Geodesy and Geophysics
! generate constant pi/180
real, parameter :: deg_to_rad = atan(1.0)/45.0
delta_lat = deg_to_rad*(latB-latA)
delta_lon = deg_to_rad*(lonB-lonA)
lat1 = deg_to_rad*(latA)
lat2 = deg_to_rad*(latB)
a = (sin(delta_lat/2))**2 + &
& cos(lat1)*cos(lat2)*(sin(delta_lon/2))**2
c = 2*asin(sqrt(a))
dist = radius*c
end function haversine
end program demo_sin
結果
> distance: 2886.4446 km
標準#
FORTRAN 77
参照#
asin(3)、 cos(3)、 tan(3)、 acosh(3)、 acos(3)、 asinh(3)、 atan2(3)、 atanh(3)、 acosh(3)、 asinh(3)、 atanh(3)
リソース#
fortran-lang intrinsic descriptions (license: MIT) @urbanjost
sinh#
名前#
sinh(3) - [数学:三角関数] 双曲線正弦関数
概要#
result = sinh(x)
elemental TYPE(kind=KIND) function sinh(x)
TYPE(kind=KIND) :: x
特性#
TYPE は 実数型 または 複素数型 です。
KIND は、関連付けられた型でサポートされている任意の種別です。
戻り値は、引数と同じ型と種別になります。
説明#
sinh(3) は x の双曲線正弦を計算します。
x の双曲線正弦は数学的に次のように定義されます。
sinh(x) = (exp(x) - exp(-x)) / 2.0
オプション#
- x
双曲線正弦を計算する値
結果#
結果は、プロセッサに依存する sinh(X) の近似値に等しい値を持ちます。 X が複素数型の場合、その虚数部はラジアン値とみなされます。
例#
サンプルプログラム
program demo_sinh
use, intrinsic :: iso_fortran_env, only : &
& real_kinds, real32, real64, real128
implicit none
real(kind=real64) :: x = - 1.0_real64
real(kind=real64) :: nan, inf
character(len=20) :: line
! basics
print *, sinh(x)
print *, (exp(x)-exp(-x))/2.0
! sinh(3) is elemental and can handle an array
print *, sinh([x,2.0*x,x/3.0])
! a NaN input returns NaN
line='NAN'
read(line,*) nan
print *, sinh(nan)
! a Inf input returns Inf
line='Infinity'
read(line,*) inf
print *, sinh(inf)
! an overflow returns Inf
x=huge(0.0d0)
print *, sinh(x)
end program demo_sinh
結果
-1.1752011936438014
-1.1752011936438014
-1.1752011936438014 -3.6268604078470190 -0.33954055725615012
NaN
Infinity
Infinity
標準#
Fortran 95、複素数引数の場合 Fortran 2008
参照#
リソース#
fortran-lang intrinsic descriptions (license: MIT) @urbanjost
tan#
名前#
tan(3) - [数学:三角関数] 正接関数
概要#
result = tan(x)
elemental TYPE(kind=KIND) function tan(x)
TYPE(kind=KIND),intent(in) :: x
特性#
x の 型 は、サポートされている任意の種類の *実数* または *複素数* です。
戻り値は、引数 **x** と同じ型と種類になります。
説明#
tan(3) は x の正接を計算します。
オプション#
- x
*実数* 入力の場合、正接を計算する角度(ラジアン)。 x が *複素数* 型の場合、その実数部はラジアン値とみなされます。
結果#
戻り値は、値 x の正接です。
例#
サンプルプログラム
program demo_tan
use, intrinsic :: iso_fortran_env, only : real_kinds, &
& real32, real64, real128
implicit none
real(kind=real64) :: x = 0.165_real64
write(*,*)x, tan(x)
end program demo_tan
結果
0.16500000000000001 0.16651386310913616
標準#
FORTRAN 77。複素数引数の場合、Fortran 2008。
参照#
atan(3)、 atan2(3)、 cos(3)、 sin(3)
fortran-lang intrinsic descriptions (license: MIT) @urbanjost
tanh#
名前#
tanh(3) - [数学:三角関数] 双曲線正接関数
概要#
result = tanh(x)
elemental TYPE(kind=KIND) function tanh(x)
TYPE(kind=KIND),intent(in) :: x
特性#
x は、*実数* または *複素数* で、プロセッサでサポートされている任意の関連種類を使用できます。
戻り値は、引数と同じ型と種別になります。
説明#
tanh(3) は x の双曲線正接を計算します。
オプション#
- x
双曲線正接を計算する値。
結果#
x の双曲線正接を返します。
x が *複素数* の場合、結果の虚数部はラジアン値とみなされます。
x が *実数* の場合、戻り値は次の範囲にあります。
-1 <= tanh(x) <= 1.
例#
サンプルプログラム
program demo_tanh
use, intrinsic :: iso_fortran_env, only : &
& real_kinds, real32, real64, real128
implicit none
real(kind=real64) :: x = 2.1_real64
write(*,*)x, tanh(x)
end program demo_tanh
結果
2.1000000000000001 0.97045193661345386
標準#
FORTRAN 77、複素数引数の場合 Fortran 2008
参照#
リソース#
fortran-lang intrinsic descriptions
random_number#
名前#
random_number(3) - [数学:乱数] 擬似乱数
概要#
call random_number(harvest)
subroutine random_number(harvest)
real,intent(out) :: harvest(..)
特性#
harvest と結果はデフォルトの *実数* 変数です。
説明#
random_number(3) は、0 <= x < 1 の範囲で一様分布から単一の擬似乱数または擬似乱数の配列を返します。
オプション#
- harvest
*実数* 型のスカラーまたは配列でなければなりません。
例#
サンプルプログラム
program demo_random_number
use, intrinsic :: iso_fortran_env, only : dp=>real64
implicit none
integer, allocatable :: seed(:)
integer :: n
integer :: first,last
integer :: i
integer :: rand_int
integer,allocatable :: count(:)
real(kind=dp) :: rand_val
call random_seed(size = n)
allocate(seed(n))
call random_seed(get=seed)
first=1
last=10
allocate(count(last-first+1))
! To have a discrete uniform distribution on the integers
! [first, first+1, ..., last-1, last] carve the continuous
! distribution up into last+1-first equal sized chunks,
! mapping each chunk to an integer.
!
! One way is:
! call random_number(rand_val)
! choose one from last-first+1 integers
! rand_int = first + FLOOR((last+1-first)*rand_val)
count=0
! generate a lot of random integers from 1 to 10 and count them.
! with a large number of values you should get about the same
! number of each value
do i=1,100000000
call random_number(rand_val)
rand_int=first+floor((last+1-first)*rand_val)
if(rand_int.ge.first.and.rand_int.le.last)then
count(rand_int)=count(rand_int)+1
else
write(*,*)rand_int,' is out of range'
endif
enddo
write(*,'(i0,1x,i0)')(i,count(i),i=1,size(count))
end program demo_random_number
結果
1 10003588
2 10000104
3 10000169
4 9997996
5 9995349
6 10001304
7 10001909
8 9999133
9 10000252
10 10000196
標準#
Fortran 95
参照#
fortran-lang intrinsic descriptions
random_seed#
名前#
random_seed(3) - [数学:乱数] 擬似乱数シーケンスの初期化
概要#
call random_seed( [size] [,put] [,get] )
subroutine random_seed( size, put, get )
integer,intent(out),optional :: size
integer,intent(in),optional :: put(*)
integer,intent(out),optional :: get(*)
特性#
size スカラー デフォルト *整数*
put ランク1 デフォルト *整数* 配列
get ランク1 デフォルト *整数* 配列
結果
説明#
random_seed(3) は、random_number が使用する擬似乱数ジェネレーターの状態を再開または照会します。
random_seed が引数なしで呼び出された場合、オペレーティングシステムから取得したランダムデータでシードされます。
オプション#
- size
put および get 引数で使用する配列の最小サイズを指定します。
- put
配列のサイズは、size 引数によって返される数以上でなければなりません。
- get
これは **intent(out)** であり、配列のサイズは **size** 引数によって返される数以上でなければなりません。
例#
サンプルプログラム
program demo_random_seed
implicit none
integer, allocatable :: seed(:)
integer :: n
call random_seed(size = n)
allocate(seed(n))
call random_seed(get=seed)
write (*, *) seed
end program demo_random_seed
結果
-674862499 -1750483360 -183136071 -317862567 682500039
349459 344020729 -1725483289
標準#
Fortran 95
参照#
fortran-lang intrinsic descriptions
exp#
名前#
exp(3) - [数学] 基数 e 指数関数
概要#
result = exp(x)
elemental TYPE(kind=KIND) function exp(x)
TYPE(kind=KIND),intent(in) :: x
特性#
x は、任意の種類の *実数* または *複素数* です。
戻り値は、x と同じ型と種類を持ちます。
説明#
exp(3) は、*e*(自然対数の底)の x 乗の値を返します。
「*e*」は *オイラー定数* としても知られています。
x が *複素数* 型の場合、その虚数部はラジアン値とみなされ、( *オイラーの公式* 参照)
cx=(re,im)
の場合
exp(cx) = exp(re) * cmplx(cos(im),sin(im),kind=kind(cx))
となります。exp(3) は log(3) の逆関数であるため、x の *実数* 成分の有効な最大 magnitude は **log(huge(x))** です。
オプション#
- x
型は *実数* または *複素数* でなければなりません。
結果#
結果の値は **e**x** で、**e** はオイラー定数です。
x が複素数型の場合、その虚数部はラジアン値とみなされます。
例#
サンプルプログラム
program demo_exp
implicit none
real :: x, re, im
complex :: cx
x = 1.0
write(*,*)"Euler's constant is approximately",exp(x)
!! complex values
! given
re=3.0
im=4.0
cx=cmplx(re,im)
! complex results from complex arguments are Related to Euler's formula
write(*,*)'given the complex value ',cx
write(*,*)'exp(x) is',exp(cx)
write(*,*)'is the same as',exp(re)*cmplx(cos(im),sin(im),kind=kind(cx))
! exp(3) is the inverse function of log(3) so
! the real component of the input must be less than or equal to
write(*,*)'maximum real component',log(huge(0.0))
! or for double precision
write(*,*)'maximum doubleprecision component',log(huge(0.0d0))
! but since the imaginary component is passed to the cos(3) and sin(3)
! functions the imaginary component can be any real value
end program demo_exp
結果
Euler's constant is approximately 2.718282
given the complex value (3.000000,4.000000)
exp(x) is (-13.12878,-15.20078)
is the same as (-13.12878,-15.20078)
maximum real component 88.72284
maximum doubleprecision component 709.782712893384
標準#
FORTRAN 77
参照#
リソース#
fortran-lang intrinsic descriptions (license: MIT) @urbanjost
log#
名前#
log(3) - [数学] 自然対数
概要#
result = log(x)
elemental TYPE(kind=KIND) function log(x)
TYPE(kind=KIND),intent(in) :: x
特性#
x は任意の *実数* または *複素数* の種類です。
結果は x と同じ型と特性です。
説明#
log(3) は x の自然対数を計算します。つまり、底が「e」の対数を計算します。
オプション#
- x
自然対数を計算する値。x が *実数* の場合、その値はゼロより大きくなければなりません。x が *複素数* の場合、その値はゼロであってはなりません。
結果#
x の自然対数。x が *複素数* 値 (r,i) の場合、虚数部「i」は次の範囲内です。
-PI < i <= PI
x の実数部がゼロ未満で、虚数部がゼロの場合、結果の虚数部は、PI の虚数部が正の実数ゼロであるか、プロセッサが正と負の実数ゼロを区別しない場合は約 PI、x の虚数部が負の実数ゼロの場合は約 -PI になります。
例#
サンプルプログラム
program demo_log
implicit none
real(kind(0.0d0)) :: x = 2.71828182845904518d0
complex :: z = (1.0, 2.0)
write(*,*)x, log(x) ! will yield (approximately) 1
write(*,*)z, log(z)
end program demo_log
結果
2.7182818284590451 1.0000000000000000
(1.00000000,2.00000000) (0.804718971,1.10714877)
標準#
FORTRAN 77
関連項目#
fortran-lang intrinsic descriptions (license: MIT) @urbanjost
log10#
名前#
log10(3) - [数学] 10 を底とする対数、または常用対数
概要#
result = log10(x)
elemental real(kind=KIND) function log10(x)
real(kind=KIND),intent(in) :: x
特性#
x は任意の種類の *実数* 値です。
結果は x と同じ型と特性です。
説明#
log10(3) は x の 10 を底とする対数を計算します。これは一般に「常用対数」と呼ばれます。
オプション#
- x
対数をとる 0 より大きい *実数* 値。
結果#
x の 10 を底とする対数
例#
サンプルプログラム
program demo_log10
use, intrinsic :: iso_fortran_env, only : real_kinds, &
& real32, real64, real128
implicit none
real(kind=real64) :: x = 10.0_real64
x = log10(x)
write(*,'(*(g0))')'log10(',x,') is ',log10(x)
! elemental
write(*, *)log10([1.0, 10.0, 100.0, 1000.0, 10000.0, &
& 100000.0, 1000000.0, 10000000.0])
end program demo_log10
結果
> log10(1.000000000000000) is .000000000000000
> 0.0000000E+00 1.000000 2.000000 3.000000 4.000000
> 5.000000 6.000000 7.000000
標準#
FORTRAN 77
関連項目#
fortran-lang intrinsic descriptions
sqrt#
名前#
sqrt(3) - [数学] 平方根関数
概要#
result = sqrt(x)
elemental TYPE(kind=KIND) function sqrt(x)
TYPE(kind=KIND),intent(in) :: x
特性#
TYPE は *実数* または *複素数* です。
KIND は、宣言された型に対して有効な任意の種類です。
結果は x と同じ特性を持ちます。
説明#
sqrt(3) は x の平方根の主値を計算します。
平方根が考慮されている数は、*被開平数* と呼ばれます。
数学では、被開平数 x の平方根は、y*y = x となる数 y です。
すべての非負の被開平数 x には、同じ大きさの 2 つの平方根があり、1 つは正、もう 1 つは負です。非負の平方根は主平方根と呼ばれます。
たとえば、9 の主平方根は 3 ですが、(-3)*(-3) も 9 になります。
負の数の平方根は複素数の特別な場合であり、*複素数* 入力では、有効な平方根を持つために被開平数の成分が正である必要はありません。
オプション#
- x
主平方根を求める被開平数。x が *実数* の場合、その値はゼロ以上でなければなりません。
結果#
x の主平方根が返されます。
*複素数* の結果の場合、実数部はゼロ以上です。
結果の実数部がゼロの場合、虚数部は x の虚数部と同じ符号になります。
例#
サンプルプログラム
program demo_sqrt
use, intrinsic :: iso_fortran_env, only : real_kinds, &
& real32, real64, real128
implicit none
real(kind=real64) :: x, x2
complex :: z, z2
! basics
x = 2.0_real64
! complex
z = (1.0, 2.0)
write(*,*)'input values ',x,z
x2 = sqrt(x)
z2 = sqrt(z)
write(*,*)'output values ',x2,z2
! elemental
write(*,*)'elemental',sqrt([64.0,121.0,30.0])
! alternatives
x2 = x**0.5
z2 = z**0.5
write(*,*)'alternatively',x2,z2
end program demo_sqrt
結果
input values 2.00000000000000 (1.000000,2.000000)
output values 1.41421356237310 (1.272020,0.7861513)
elemental 8.000000 11.00000 5.477226
alternatively 1.41421356237310 (1.272020,0.7861513)
標準#
FORTRAN 77
関連項目#
fortran-lang intrinsic descriptions (license: MIT) @urbanjost
hypot#
名前#
hypot(3) - [数学] ユークリッド距離(点と原点の間の距離)を返します。
概要#
result = hypot(x, y)
elemental real(kind=KIND) function hypot(x,y)
real(kind=KIND),intent(in) :: x
real(kind=KIND),intent(in) :: y
特性#
x、y、および結果はすべて *実数* で、同じ **kind** でなければなりません。
説明#
hypot(3) はユークリッド距離関数と呼ばれます。これは 다음과 같습니다.
sqrt(x**2+y**2)
不必要なアンダーフローまたはオーバーフローなし。
数学では、ユークリッド空間における 2 つの点間の*ユークリッド距離* は、2 つの点間の線分の長さです。
hypot(x,y) は、点 **<x,y>** と原点の間の距離を返します。
オプション#
- x
型は *実数* でなければなりません。
- y
型と kind 型パラメータは、x と同じでなければなりません。
結果#
戻り値は、x と同じ型と kind 型パラメータを持ちます。
結果は、点 **<x,y>** から原点 **<0.0,0.0>** までの距離の正の大きさです。
例#
サンプルプログラム
program demo_hypot
use, intrinsic :: iso_fortran_env, only : &
& real_kinds, real32, real64, real128
implicit none
real(kind=real32) :: x, y
real(kind=real32),allocatable :: xs(:), ys(:)
integer :: i
character(len=*),parameter :: f='(a,/,SP,*(3x,g0,1x,g0:,/))'
x = 1.e0_real32
y = 0.5e0_real32
write(*,*)
write(*,'(*(g0))')'point <',x,',',y,'> is ',hypot(x,y)
write(*,'(*(g0))')'units away from the origin'
write(*,*)
! elemental
xs=[ x, x**2, x*10.0, x*15.0, -x**2 ]
ys=[ y, y**2, -y*20.0, y**2, -y**2 ]
write(*,f)"the points",(xs(i),ys(i),i=1,size(xs))
write(*,f)"have distances from the origin of ",hypot(xs,ys)
write(*,f)"the closest is",minval(hypot(xs,ys))
end program demo_hypot
結果
point <1.00000000,0.500000000> is 1.11803401
units away from the origin
the points
+1.00000000 +0.500000000
+1.00000000 +0.250000000
+10.0000000 -10.0000000
+15.0000000 +0.250000000
-1.00000000 -0.250000000
have distances from the origin of
+1.11803401 +1.03077638
+14.1421356 +15.0020828
+1.03077638
the closest is
+1.03077638
標準#
標準#
関連項目#
fortran-lang intrinsic descriptions (license: MIT) @urbanjost
bessel_j0#
名前#
bessel_j0(3) - [数学] 0 次の第 1 種ベッセル関数
概要#
result = bessel_j0(x)
elemental real(kind=KIND) function bessel_j0(x)
real(kind=KIND),intent(in) :: x
特性#
KIND は、*実数* 型でサポートされている任意の KIND です。
結果は x と同じ型と kind です。
説明#
bessel_j0(3) は、x の 0 次の第 1 種ベッセル関数を計算します。
オプション#
- x
操作対象の値。
結果#
**x** の 0 次の第 1 種ベッセル関数。結果は **-0.4027 <= bessel(0,x) <= 1** の範囲にあります。
例#
サンプルプログラム
program demo_bessel_j0
use, intrinsic :: iso_fortran_env, only : real_kinds, &
& real32, real64, real128
implicit none
real(kind=real64) :: x
x = 0.0_real64
x = bessel_j0(x)
write(*,*)x
end program demo_bessel_j0
結果
1.0000000000000000
標準#
標準#
関連項目#
bessel_j1(3), bessel_jn(3), bessel_y0(3), bessel_y1(3), bessel_yn(3)
fortran-lang intrinsic descriptions
bessel_j1#
名前#
**bessel_j1**(3) - [数学] 1 次の第 1 種ベッセル関数
**概要**#
result = bessel_j1(x)
elemental real(kind=KIND) function bessel_j1(x)
real(kind=KIND),intent(in) :: x
**特性**#
KIND は、サポートされている任意の *実数* KIND です。
結果は **x** と同じ型と kind です。
**説明**#
**bessel_j1**(3) は **x** の 1 次の第 1 種ベッセル関数を計算します。
**オプション**#
- x
型は *実数* でなければなりません。
**結果**#
戻り値は *実数* 型で、**-0.5818 <= bessel(0,x) <= 0.5818** の範囲にあります。**x** と同じ kind です。
**例**#
サンプルプログラム
program demo_bessel_j1
use, intrinsic :: iso_fortran_env, only : real_kinds, &
& real32, real64, real128
implicit none
real(kind=real64) :: x = 1.0_real64
x = bessel_j1(x)
write(*,*)x
end program demo_bessel_j1
結果
0.44005058574493350
**標準**#
標準#
**関連項目**#
**bessel_j0**(3), **bessel_jn**(3), **bessel_y0**(3), **bessel_y1**(3), **bessel_yn**(3)
fortran-lang intrinsic descriptions
bessel_jn#
**名前**#
**bessel_jn**(3) - [数学] 第 1 種ベッセル関数
**概要**#
result = bessel_jn(n, x)
elemental real(kind=KIND) function bessel_jn(n,x)
integer(kind=**),intent(in) :: n
real(kind=KIND),intent(in) :: x
KIND は *実数* 型の任意の有効な値です。
**x** は *実数* です。
戻り値は、x と同じ型と種類を持ちます。
result = bessel_jn(n1, n2, x)
real(kind=KIND) function bessel_jn(n1, n2, ,x)
integer(kind=**),intent(in) :: n1
integer(kind=**),intent(in) :: n2
real(kind=KIND),intent(in) :: x
**n1** は *整数* です。
**n2** は *整数* です。
**x** は *実数* です。
戻り値は、x と同じ型と種類を持ちます。
**説明**#
**bessel_jn( n, x )** は **x** の **n** 次の第 1 種ベッセル関数を計算します。
**bessel_jn(n1, n2, x)** は、**n1** から **n2** までの次数の第 1 種ベッセル関数を含む配列を返します。
**オプション**#
- n
非負のスカラー整数。
- n1
非負のスカラー *整数*。
- n2
非負のスカラー *整数*。
- x
**bessel_jn(n,x)** の場合はスカラー、**bessel_jn(n1, n2, x)** の場合は配列でなければなりません。
**結果**#
BESSEL_JN (N, X) の結果値は、X の N 次の第 1 種ベッセル関数のプロセッサ依存の近似値です。
BESSEL_JN (N1, N2, X) の結果は、範囲 MAX (N2-N1+1, 0) を持つランク 1 の配列です。BESSEL_JN (N1, N2, X) の結果値の要素 i は、X の N1+i-1 次の第 1 種ベッセル関数のプロセッサ依存の近似値です。
**例**#
サンプルプログラム
program demo_bessel_jn
use, intrinsic :: iso_fortran_env, only : real_kinds, &
& real32, real64, real128
implicit none
real(kind=real64) :: x = 1.0_real64
x = bessel_jn(5,x)
write(*,*)x
end program demo_bessel_jn
結果
2.4975773021123450E-004
**標準**#
標準#
**関連項目**#
**bessel_j0**(3), **bessel_j1**(3), **bessel_y0**(3), **bessel_y1**(3), **bessel_yn**(3)
fortran-lang intrinsic descriptions
bessel_y0#
**名前**#
**bessel_y0**(3) - [数学] 0 次の第 2 種ベッセル関数
**概要**#
result = bessel_y0(x)
elemental real(kind=KIND) function bessel_y0(x)
real(kind=KIND),intent(in) :: x
**特性**#
KIND は、サポートされている任意の *実数* KIND です。
結果の特性(型、kind)は **x** と同じです。
説明#
bessel_y0(3) は、**x** の0次第二種ベッセル関数を計算します。
オプション#
- x
型は *実数* でなければなりません。値はゼロより大きくなければなりません。
結果#
戻り値の型は *実数* です。**x** と同じ kind を持ちます。
例#
サンプルプログラム
program demo_bessel_y0
use, intrinsic :: iso_fortran_env, only : real_kinds, &
& real32, real64, real128
implicit none
real(kind=real64) :: x = 0.0_real64
x = bessel_y0(x)
write(*,*)x
end program demo_bessel_y0
結果
-Infinity
標準#
標準#
関連項目#
bessel_j0(3), bessel_j1(3), bessel_jn(3), bessel_y1(3), bessel_yn(3)
fortran-lang intrinsic descriptions
bessel_y1#
名前#
bessel_y1(3) - [数学] 1次第二種ベッセル関数
概要#
result = bessel_y1(x)
elemental real(kind=KIND) function bessel_y1(x)
real(kind=KIND),intent(in) :: x
特性#
KIND は、サポートされている任意の *実数* KIND です。
結果の特性(型、kind)は **x** と同じです。
説明#
bessel_y1(3) は、**x** の1次第二種ベッセル関数を計算します。
オプション#
- x
型は *実数* でなければなりません。値はゼロより大きくなければなりません。
結果#
戻り値は *実数* です。**x** と同じ kind を持ちます。
例#
サンプルプログラム
program demo_bessel_y1
use, intrinsic :: iso_fortran_env, only : real_kinds, &
& real32, real64, real128
implicit none
real(kind=real64) :: x = 1.0_real64
write(*,*)x, bessel_y1(x)
end program demo_bessel_y1
結果
> 1.00000000000000 -0.781212821300289
標準#
標準#
関連項目#
bessel_j0(3), bessel_j1(3), bessel_jn(3), bessel_y0(3), bessel_yn(3)
fortran-lang intrinsic descriptions
bessel_yn#
名前#
bessel_yn(3) - [数学] 第二種ベッセル関数
概要#
result = bessel_yn(n, x)
elemental real(kind=KIND) function bessel_yn(n,x)
integer(kind=**),intent(in) :: n
real(kind=KIND),intent(in) :: x
特性#
n は *整数* です。
**x** は *実数* です。
戻り値は、x と同じ型と種類を持ちます。
result = bessel_yn(n1, n2, x)
real(kind=KIND) function bessel_yn(n1, n2, ,x)
integer(kind=**),intent(in) :: n1
integer(kind=**),intent(in) :: n2
real(kind=KIND),intent(in) :: x
**n1** は *整数* です。
**n2** は *整数* です。
**x** は *実数* です。
戻り値は、x と同じ型と種類を持ちます。
説明#
bessel_yn(n, x) は、**x** の **n** 次第二種ベッセル関数を計算します。
bessel_yn(n1, n2, x) は、**n1** から **n2** までの次数の第一種ベッセル関数の配列を返します。
オプション#
- n
*整数* 型のスカラーまたは配列で、非負でなければなりません。
- n1
非負の *整数* 型のスカラーで、非負でなければなりません。
- n2
非負の *整数* 型のスカラーで、非負でなければなりません。
- x
非負の *実数* 値。**bessel_yn(n1, n2, x)** は要素関数ではないため、スカラーでなければなりません。
結果#
BESSEL_YN (N, X) の結果値は、X の N 次第二種ベッセル関数のプロセッサ依存の近似値です。
BESSEL_YN (N1, N2, X) の結果は、範囲 **MAX (N2-N1+1, 0)** のランク1配列です。BESSEL_YN (N1, N2, X) の結果値の要素 i は、X の N1+i-1 次第二種ベッセル関数のプロセッサ依存の近似値です。
例#
サンプルプログラム
program demo_bessel_yn
use, intrinsic :: iso_fortran_env, only : real_kinds, &
& real32, real64, real128
implicit none
real(kind=real64) :: x = 1.0_real64
write(*,*) x,bessel_yn(5,x)
end program demo_bessel_yn
結果
1.0000000000000000 -260.40586662581222
標準#
標準#
関連項目#
bessel_j0(3), bessel_j1(3), bessel_jn(3), bessel_y0(3), bessel_y1(3)
fortran-lang intrinsic descriptions
erf#
名前#
erf(3) - [数学] 誤差関数
概要#
result = erf(x)
elemental real(kind=KIND) function erf(x)
real(kind=KIND),intent(in) :: x
特性#
**x** は *実数* 型です。
結果は **x** と同じ *型* と *kind* です。
説明#
erf(3) は、次のように定義される **x** の誤差関数を計算します。
オプション#
- x
型は *実数* でなければなりません。
結果#
戻り値は、**x** と同じ kind の *実数* 型で、**-1** <= **erf**(x) <= **1** の範囲にあります。
例#
サンプルプログラム
program demo_erf
use, intrinsic :: iso_fortran_env, only : real_kinds, &
& real32, real64, real128
implicit none
real(kind=real64) :: x = 0.17_real64
write(*,*)x, erf(x)
end program demo_erf
結果
0.17000000000000001 0.18999246120180879
標準#
標準#
関連項目#
資料#
fortran-lang intrinsic descriptions
erfc#
名前#
erfc(3) - [数学] 相補誤差関数
概要#
result = erfc(x)
elemental real(kind=KIND) function erfc(x)
real(kind=KIND),intent(in) :: x
特性#
**x** は *実数* 型で、任意の有効な kind を持ちます。
**KIND** は *実数* 型で有効な任意の値です。
結果は **x** と同じ特性を持ちます。
説明#
erfc(3) は、**x** の相補誤差関数を計算します。簡単に言うと、これは **1 - erf(x)** と同等ですが、大きな **x** に対して **erf(x)** を呼び出し、結果から **1** を減算すると相対精度が極端に低下するため、**erfc** が用意されています。
erfc(x) は次のように定義されます。
オプション#
- x
型は *実数* でなければなりません。
結果#
戻り値は *実数* 型で、**x** と同じ kind です。範囲は
0 \<= **erfc**(x) \<= 2.
であり、**x** の相補誤差関数 ( **1-erf(x)** ) のプロセッサ依存の近似値です。
例#
サンプルプログラム
program demo_erfc
use, intrinsic :: iso_fortran_env, only : &
& real_kinds, real32, real64, real128
implicit none
real(kind=real64) :: x = 0.17_real64
write(*,'(*(g0))')'X=',x, ' ERFC(X)=',erfc(x)
write(*,'(*(g0))')'equivalently 1-ERF(X)=',1-erf(x)
end program demo_erfc
結果
> X=.1700000000000000 ERFC(X)=.8100075387981912
> equivalently 1-ERF(X)=.8100075387981912
標準#
標準#
関連項目#
資料#
fortran-lang intrinsic descriptions (license: MIT) @urbanjost
erfc_scaled#
名前#
erfc_scaled(3) - [数学] スケールされた相補誤差関数
概要#
result = erfc_scaled(x)
elemental real(kind=KIND) function erfc_scaled(x)
real(kind=KIND),intent(in) :: x
特性#
**x** は任意の有効な kind の *実数* 型です。
**KIND** は *実数* 型で有効な任意の kind です。
結果は **x** と同じ特性を持ちます。
説明#
erfc_scaled(3) は、**x** の指数スケールされた相補誤差関数を計算します。
erfc_scaled(x)=exp(x*x)erfc(x)
注記1#
相補誤差関数は exp(-X2)/(X/PI) に漸近します。そのため、ISO/IEC/IEEE 60559:2011 単精度演算を使用する場合、約 X >= 9 でアンダーフローします。指数スケールされた相補誤差関数は 1/(X PI) に漸近します。そのため、X > HUGE (X)/PI までアンダーフローしません。
オプション#
**x** は **erfc** 関数を適用する値です。
結果#
**x** の指数スケールされた相補誤差関数の近似値です。
例#
サンプルプログラム
program demo_erfc_scaled
implicit none
real(kind(0.0d0)) :: x = 0.17d0
x = erfc_scaled(x)
print *, x
end program demo_erfc_scaled
結果
> 0.833758302149981
標準#
標準#
関連項目#
fortran-lang intrinsic descriptions (license: MIT) @urbanjost
gamma#
名前#
gamma(3) - [数学] ガンマ関数。正の整数に対して階乗を返します。
概要#
result = gamma(x)
elemental real(kind=KIND) function gamma( x)
type(real,kind=KIND),intent(in) :: x
特性#
**x** は *実数* 値です。
**x** と同じ kind の *実数* 値を返します。
説明#
**gamma(x) **は、**x** のガンマ関数を計算します。正の整数値 **n** に対して、ガンマ関数は階乗の計算に使用できます。 **(n-1)! == gamma(real(n))** 。 つまり
n! == gamma(real(n+1))
オプション#
- x
*実数* 型で、ゼロまたは負の整数であってはなりません。
結果#
戻り値は、*x* と同じ kind の *実数* 型です。結果は、**x** のガンマ関数のプロセッサ依存の近似値です。
例#
サンプルプログラム
program demo_gamma
use, intrinsic :: iso_fortran_env, only : wp=>real64
implicit none
real :: x, xa(4)
integer :: i
x = gamma(1.0)
write(*,*)'gamma(1.0)=',x
! elemental
xa=gamma([1.0,2.0,3.0,4.0])
write(*,*)xa
write(*,*)
! gamma(3) is related to the factorial function
do i=1,20
! check value is not too big for default integer type
if(factorial(i).gt.huge(0))then
write(*,*)i,factorial(i)
else
write(*,*)i,factorial(i),int(factorial(i))
endif
enddo
! more factorials
FAC: block
integer,parameter :: n(*)=[0,1,5,11,170]
integer :: j
do j=1,size(n)
write(*,'(*(g0,1x))')'factorial of', n(j),' is ', &
& product([(real(i,kind=wp),i=1,n(j))]), &
& gamma(real(n(j)+1,kind=wp))
enddo
endblock FAC
contains
function factorial(i) result(f)
integer,parameter :: dp=kind(0d0)
integer,intent(in) :: i
real :: f
if(i.le.0)then
write(*,'(*(g0))')'<ERROR> gamma(3) function value ',i,' <= 0'
stop '<STOP> bad value in gamma function'
endif
f=gamma(real(i+1))
end function factorial
end program demo_gamma
結果
gamma(1.0)= 1.000000
1.000000 1.000000 2.000000 6.000000
1 1.000000 1
2 2.000000 2
3 6.000000 6
4 24.00000 24
5 120.0000 120
6 720.0000 720
7 5040.000 5040
8 40320.00 40320
9 362880.0 362880
10 3628800. 3628800
11 3.9916800E+07 39916800
12 4.7900160E+08 479001600
13 6.2270208E+09
14 8.7178289E+10
15 1.3076744E+12
16 2.0922791E+13
17 3.5568741E+14
18 6.4023735E+15
19 1.2164510E+17
20 2.4329020E+18
factorial of 0 is 1.000000000000000 1.000000000000000
factorial of 1 is 1.000000000000000 1.000000000000000
factorial of 5 is 120.0000000000000 120.0000000000000
factorial of 11 is 39916800.00000000 39916800.00000000
factorial of 170 is .7257415615307994E+307 .7257415615307999E+307
標準#
標準#
関連項目#
ガンマ関数の対数: log_gamma(3)
資料#
fortran-lang intrinsic descriptions
log_gamma#
名前#
log_gamma(3) - [数学] ガンマ関数の絶対値の対数
概要#
result = log_gamma(x)
elemental real(kind=KIND) function log_gamma(x)
real(kind=KIND),intent(in) :: x
特性#
x は任意の *実数* 型です。
戻り値は x と同じ型および種別です。
説明#
log_gamma(3) は、ガンマ関数の絶対値の自然対数を計算します。
オプション#
- x
結果を算出するために、負の値またはゼロ値を使用しないでください。
結果#
結果は、x のガンマ関数の絶対値の自然対数に対するプロセッサ依存の近似値になります。
例#
サンプルプログラム
program demo_log_gamma
implicit none
real :: x = 1.0
write(*,*)x,log_gamma(x) ! returns 0.0
write(*,*)x,log_gamma(3.0) ! returns 0.693 (approximately)
end program demo_log_gamma
結果
> 1.000000 0.0000000E+00
> 1.000000 0.6931472
標準#
標準#
関連項目#
ガンマ関数: gamma(3)
fortran-lang intrinsic descriptions
log_gamma#
名前#
log_gamma(3) - [数学] ガンマ関数の絶対値の対数
概要#
result = log_gamma(x)
elemental real(kind=KIND) function log_gamma(x)
real(kind=KIND),intent(in) :: x
特性#
x は任意の *実数* 型です。
戻り値は x と同じ型および種別です。
説明#
log_gamma(3) は、ガンマ関数の絶対値の自然対数を計算します。
オプション#
- x
結果を算出するために、負の値またはゼロ値を使用しないでください。
結果#
結果は、x のガンマ関数の絶対値の自然対数に対するプロセッサ依存の近似値になります。
例#
サンプルプログラム
program demo_log_gamma
implicit none
real :: x = 1.0
write(*,*)x,log_gamma(x) ! returns 0.0
write(*,*)x,log_gamma(3.0) ! returns 0.693 (approximately)
end program demo_log_gamma
結果
> 1.000000 0.0000000E+00
> 1.000000 0.6931472
標準#
標準#
関連項目#
ガンマ関数: gamma(3)
fortran-lang intrinsic descriptions
norm2#
名前#
norm2(3) - [数学] ユークリッドベクトルノルム
概要#
result = norm2(array, [dim])
real(kind=KIND) function norm2(array, dim)
real(kind=KIND),intent(in) :: array(..)
integer(kind=**),intent(in),optional :: dim
特性#
array は *実数* 型の配列です。
dim は *整数* 型のスカラーです。
結果は array と同じ型です。
説明#
norm2(3) は、次元 dim に沿った array のユークリッドベクトルノルム(L_2 ノルムまたは一般化 L ノルム)を計算します。
オプション#
- array
L_2 ノルム計算の入力値の配列
- dim
1 から rank(array) までの範囲の値。
結果#
dim がない場合、array の要素の平方和の平方根を持つスカラーが返されます。
それ以外の場合、ランク n-1 の配列が返されます。ここで、n は array のランクと等しく、形状は次元 DIM が削除された array の形状に似ています。
Case (i): The result of NORM2 (X) has a value equal to a
processor-dependent approximation to the generalized
L norm of X, which is the square root of the sum of
the squares of the elements of X. If X has size zero,
the result has the value zero.
Case (ii): The result of NORM2 (X, DIM=DIM) has a value equal
to that of NORM2 (X) if X has rank one. Otherwise,
the resulting array is reduced in rank with dimension
**dim** removed, and each remaining elment is the
result of NORM2(X) for the values along dimension
**dim**.
プロセッサは、不必要なオーバーフローまたはアンダーフローなしで結果を計算することをお勧めします。
例#
サンプルプログラム
program demo_norm2
implicit none
integer :: i
real :: x(2,3) = reshape([ &
1, 2, 3, &
4, 5, 6 &
],shape(x),order=[2,1])
write(*,*) 'input in row-column order'
write(*,*) 'x='
write(*,'(4x,3f4.0)')transpose(x)
write(*,*)
write(*,*) 'norm2(x)=',norm2(x)
write(*,*) 'which is equivalent to'
write(*,*) 'sqrt(sum(x**2))=',sqrt(sum(x**2))
write(*,*)
write(*,*) 'for reference the array squared is'
write(*,*) 'x**2='
write(*,'(4x,3f4.0)')transpose(x**2)
write(*,*)
write(*,*) 'norm2(x,dim=1)=',norm2(x,dim=1)
write(*,*) 'norm2(x,dim=2)=',norm2(x,dim=2)
write(*,*) '(sqrt(sum(x(:,i)**2)),i=1,3)=',(sqrt(sum(x(:,i)**2)),i=1,3)
write(*,*) '(sqrt(sum(x(i,:)**2)),i=1,2)=',(sqrt(sum(x(i,:)**2)),i=1,2)
end program demo_norm2
結果
> input in row-column order
> x=
> 1. 2. 3.
> 4. 5. 6.
>
> norm2(x)= 9.539392
> which is equivalent to
> sqrt(sum(x**2))= 9.539392
>
> for reference the array squared is
> x**2=
> 1. 4. 9.
> 16. 25. 36.
>
> norm2(x,dim=1)= 4.123106 5.385165 6.708204
> norm2(x,dim=2)= 3.741657 8.774964
> (sqrt(sum(x(:,i)**2)),i=1,3)= 4.123106 5.385165 6.708204
> (sqrt(sum(x(i,:)**2)),i=1,2)= 3.741657 8.774964
標準#
標準#
関連項目#
fortran-lang intrinsic descriptions (license: MIT) @urbanjost