Ma`lumotlar : 1092
Xabarlar soni: 314
Bugun: 18.4.2024
Soat: 3:22
Fortran90 tilida takrorlanuvchi algoritm
Muallif: Mengliyev Sh.
Qo`shilgan sana: 2016-11-01
Fortran90 tilida takrorlanuvchi algoritmlar
program main
call vaqt ( )
write ( *, '(a)' ) ' FORTRAN90 versiyada.'
call test01 ( )
stop
end
subroutine test01 ( )
real ( kind = 8 ) factor
real ( kind = 8 ) fx
real ( kind = 8 ) fx2
integer ( kind = 4 ) i
integer ( kind = 4 ) j
integer ( kind = 4 ) n_data
integer ( kind = 4 ) :: term_num = 5
real ( kind = 8 ) x
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'TEST01:'
write ( *, '(a)' ) ' X EXP(X) Approx(X) Error'
write ( *, '(a)' ) ' '
n_data = 0
do
call exp_qism ( n_data, x, fx )
if ( n_data == 0 ) then
exit
end if
fx2 = 1.0D+00
factor = 1.0D+00
do i = 1, term_num
factor = 1.0D+00
do j = 1, i
factor = factor * j
end do
fx2 = fx2 + x**i / factor
end do
write ( *, '(2x,g14.6,2x,g14.6,2x,g14.6,2x,g10.4)' ) &
x, fx, fx2, abs ( fx - fx2 )
end do
return
end
subroutine exp_qism ( n_data, x, fx )
integer ( kind = 4 ), parameter :: n_max = 24
real ( kind = 8 ) fx
real ( kind = 8 ), save, dimension ( n_max ) :: fx_vec = (/ &
0.000045399929762484851536D+00, &
0.0067379469990854670966D+00, &
0.36787944117144232160D+00, &
1.0000000000000000000D+00, &
1.0000000100000000500D+00, &
1.0001000050001666708D+00, &
1.0010005001667083417D+00, &
1.0100501670841680575D+00, &
1.1051709180756476248D+00, &
1.2214027581601698339D+00, &
1.3498588075760031040D+00, &
1.4918246976412703178D+00, &
1.6487212707001281468D+00, &
1.8221188003905089749D+00, &
2.0137527074704765216D+00, &
2.2255409284924676046D+00, &
2.4596031111569496638D+00, &
2.7182818284590452354D+00, &
7.3890560989306502272D+00, &
23.140692632779269006D+00, &
148.41315910257660342D+00, &
22026.465794806716517D+00, &
4.8516519540979027797D+08, &
2.3538526683701998541D+17 /)
integer ( kind = 4 ) n_data
real ( kind = 8 ) x
real ( kind = 8 ), save, dimension ( n_max ) :: x_vec = (/ &
-10.0D+00, &
-5.0D+00, &
-1.0D+00, &
0.0D+00, &
0.00000001D+00, &
0.0001D+00, &
0.001D+00, &
0.01D+00, &
0.1D+00, &
0.2D+00, &
0.3D+00, &
0.4D+00, &
0.5D+00, &
0.6D+00, &
0.7D+00, &
0.8D+00, &
0.9D+00, &
1.0D+00, &
2.0D+00, &
3.1415926535897932385D+00, &
5.0D+00, &
10.0D+00, &
20.0D+00, &
40.0D+00 /)
if ( n_data < 0 ) then
n_data = 0
end if
n_data = n_data + 1
if ( n_max < n_data ) then
n_data = 0
x = 0.0D+00
fx = 0.0D+00
else
x = x_vec(n_data)
fx = fx_vec(n_data)
end if
return
end
subroutine vaqt ( )
character ( len = 8 ) ampm
integer ( kind = 4 ) d
integer ( kind = 4 ) h
integer ( kind = 4 ) m
integer ( kind = 4 ) mm
character ( len = 9 ), parameter, dimension(12) :: month = (/ &
'January ', 'February ', 'March ', 'April ', &
'May ', 'June ', 'July ', 'August ', &
'September', 'October ', 'November ', 'December ' /)
integer ( kind = 4 ) n
integer ( kind = 4 ) s
integer ( kind = 4 ) values(8)
integer ( kind = 4 ) y
call date_and_time ( values = values )
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
write ( *, '(i2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) &
d, trim ( month(m) ), y, h, ':', n, ':', s, '.', mm, trim ( ampm )
return
end
2223 marta o`qildi.