Professional Documents
Culture Documents
Tugaa Subprogram - Defri Prayoga - 1910911037
Tugaa Subprogram - Defri Prayoga - 1910911037
Nama:defri prayoga
Bp :1910911037
Penjelasan tentang:
Annulus_monte_carlo_test
function annulus_area ( r1, r2 )
!
***************************************************************************
**80
!
!! annulus_area() computes the area of a circular annulus in 2D.
!
! Discussion:
!
! A circular annulus with center (XC,YC), inner radius R1 and
! outer radius R2, is the set of points (X,Y) so that
!
! R1^2 <= (X-XC)^2 + (Y-YC)^2 <= R2^2
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 26 August 2021
!
! Author:
!
! John Burkardt
!
! Input:
!
! real ( kind = rk ) R1, R2, the inner and outer radii of the annulus.
! 0.0 <= R1 <= R2.
!
! Output:
!
! real ( kind = rk ) ANNULUS_AREA, the area of the annulus.
!
implicit none
if ( r2 < r1 ) then
write ( *, '(a)' ) ''
write ( *, '(a)' ) 'ANNULUS_AREA - Fatal error!'
write ( *, '(a)' ) ' Outer radius R1 < R1 = inner radius.'
stop 1
end if
value = r8_pi * ( r2 + r1 ) * ( r2 - r1 )
annulus_area = value
return
end
subroutine annulus_sample ( center, r1, r2, n, p )
!
***************************************************************************
**80
!
!! annulus_sample() samples a circular annulus.
!
! Discussion:
!
! A circular annulus with center PC, inner radius R1 and
! outer radius R2, is the set of points P so that
!
! R1^2 <= (P(1)-PC(1))^2 + (P(2)-PC(2))^2 <= R2^2
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 26 August 2021
!
! Author:
!
! John Burkardt
!
! Reference:
!
! Peter Shirley,
! Nonuniform Random Point Sets Via Warping,
! Graphics Gems, Volume III,
! edited by David Kirk,
! AP Professional, 1992,
! ISBN: 0122861663,
! LC: T385.G6973.
!
! Input:
!
! real ( kind = rk ) CENTER(2), the center.
!
! real ( kind = rk ) R1, R2, the inner and outer radii.
! 0.0 <= R1 <= R2.
!
! integer N, the number of points to generate.
!
! Output:
!
! real ( kind = rk ) P(2,N), sample points.
!
implicit none
integer n
integer, parameter :: rk = kind ( 1.0D+00 )
if ( r2 < r1 ) then
write ( *, '(a)' ) ''
write ( *, '(a)' ) 'ANNULUS_SAMPLE - Fatal error!'
write ( *, '(a)' ) ' Outer radius R1 < R1 = inner radius.'
stop 1
end if
return
end
subroutine disk01_monomial_integral ( e, integral )
!
***************************************************************************
**80
!
!! disk01_monomial_integral() returns monomial integrals in the unit disk
in 2D.
!
! Discussion:
!
! The integration region is
!
! X^2 + Y^2 <= 1.
!
! The monomial is F(X,Y) = X^E(1) * Y^E(2).
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 02 January 2014
!
! Author:
!
! John Burkardt
!
! Input:
!
! integer E(2), the exponents of X and Y in the
! monomial. Each exponent must be nonnegative.
!
! Output:
!
! real ( kind = rk ) INTEGRAL, the integral.
!
implicit none
integral = 0.0_rk
else
integral = 2.0_rk
do i = 1, 2
arg = 0.5_rk * real ( e(i) + 1, kind = rk )
integral = integral * gamma ( arg )
end do
return
end
subroutine monomial_value ( m, n, e, x, value )
!
***************************************************************************
**80
!
!! monomial_value() evaluates a monomial.
!
! Discussion:
!
! This routine evaluates a monomial of the form
!
! product ( 1 <= i <= m ) x(i)^e(i)
!
! where the exponents are nonnegative integers. Note that
! if the combination 0^0 is encountered, it should be treated
! as 1.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 02 January 2014
!
! Author:
!
! John Burkardt
!
! Input:
!
! integer M, the spatial dimension.
!
! integer N, the number of points at which the
! monomial is to be evaluated.
!
! integer E(M), the exponents.
!
! real ( kind = rk ) X(M,N), the point coordinates.
!
! Output:
!
! real ( kind = rk ) VALUE(N), the value of the monomial.
!
implicit none
integer m
integer n
integer, parameter :: rk = kind ( 1.0D+00 )
integer e(m)
integer i
real ( kind = rk ) value(n)
real ( kind = rk ) x(m,n)
value(1:n) = 1.0_rk
do i = 1, m
if ( 0 /= e(i) ) then
value(1:n) = value(1:n) * x(i,1:n) ** e(i)
end if
end do
return
end
subroutine timestamp ( )
!
***************************************************************************
**80
!
!! timestamp() prints the current YMDHMS date as a time stamp.
!
! Example:
!
! 31 May 2001 9:45:54.872 AM
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 02 January 2014
!
! Author:
!
! John Burkardt
!
implicit none
y = values(1)
m = values(2)
d = values(3)
h = values(5)
n = values(6)
s = values(7)
mm = values(8)
if ( h < 12 ) then
ampm = 'AM'
else if ( h == 12 ) then
if ( n == 0 .and. s == 0 ) then
ampm = 'Noon'
else
ampm = 'PM'
end if
else
h = h - 12
if ( h < 12 ) then
ampm = 'PM'
else if ( h == 12 ) then
if ( n == 0 .and. s == 0 ) then
ampm = 'Midnight'
else
ampm = 'AM'
end if
end if
end if
return
end
penjelasan:
kode FORTRAN90 yang menggunakan metode Monte Carlo untuk memperkirakan integral
suatu fungsi di atas bagian dalam anulus melingkar dalam 2D.
5 subprogram = 1 function + 4 subroutine
function annulus_area berguna untuk menghitung luas anulus lingkaran dalam 2D.
subroutine annulus_sample untuk sampel anulus melingkar.
subroutine disk01_monomial_integral untuk mengembalikan integral monomial dalam unit
disk dalam 2D
subroutine monomial_value untuk mengevaluasi monomial
subroutine timestamp untuk menampilkan cap waktu dengan format TBHJMD