Современный Фортран_учебник
.pdf52
13. - Write?
Real, dimension(1:12, 1:12):: A
Write(*,*) A(12,12)
14. - Write?
Real, dimension(1:12, 1:12):: A
Write (*,11) A(10:12, 10:12)
11Format(F10.2)
15.& 3 * 100 5 -
Format . :
a)« ! »;
b). .
# $& !
1.! ! #
. A.
! -# ! .
# + .
2.5 ! .
. " 3 :
Real,dimension(1:8, 1:10):: A
3.data.txt -
|
11 |
12 |
13 |
14 |
15 |
|
21 |
22 |
23 |
24 |
25 |
|
31 |
32 |
33 |
34 |
35 |
- . ( ) !
, ! ?
Integer, dimension(3,5):: Mas = 0
Open(1,file = ’data.txt’) Read(1,*) Mas(2, 1:5:2)
! $ %
End
% 11.
$' ! «- »
1
! ., #
« » (.
). $ « » !
, # . (. a11).
.
53
2
! B . ,. / . bik !
. , ,
i,k .
! +* + .
3
& ! B ! A, . # -
. 1 A # ,
*, :
-A, * # B;
-+ B.
4
! ., *
!, ! # . -
+ .
5
5 ! ! ! .-
. ( , * # -
! # ., ! +* ! 0.
.
6
0 ! # +
. . :
- ! # + . ( ); - .
7
! -
! # . !
. .
8
! .
! ! .
. ; ! . . :
-;
-.
54
9
! B . ,. / . bik !
. , ,
i,k .
! +* + .
10
0 ! ! + .
! # . :
-# .;
-+ .
11
1 ! # . !
! # ., ! -
! # . , !
! # .. ' -
! . :
- ;
-.
12
* # # .. ! !
. .
13
' ! , , - * ., . 1 #
. , *. :
-# *;
-+ .
14
! + B .
,. / . bik
! . , ,
i,k -
.
! +* + .
55
15
' ! ,
! (! ! -). ' # . *,
+ .
16
1 , ! + .-
, ! B , -
, - . :
-, # ;
-+ .
17
5 ! ! -
! # .. ' ! # .-
*. :
-! # . # *;
-! +* .
18
0 #
# . *!+ # -
! , ! + . -
# . + -
* .
19
! B . ,. / . bik ! -
! . , , -
i,k .
! +* + .
20
0 ! # .
. :
-! # . ;
-.
56
21
0 ! + .
! . .
, # * .
-# # .;
-+ .
22
,, !
# , ! - .,
" - ., 3, D - ., 5.
! . . -
.
23
1 ! ! # .
! ! # ., ! -
# . , -
# . . 1 -
! # ! # ., *,
:
-! # ! # . ;
-! +* .
24
! B . ,. / . bik ! -
! . , , -
i,k .
! +* + .
25
' ! ! .
. ( , * # # -
! # ., *. :
-., # ;
-+ .
57
26
! + B .
,. / . bik
! ! . ,
, i,k
. ! +* + .
27
5 ! ! . A
. . aij ! . ai-1,j , ai+1,j , ai,j-1 , ai,j+1 . !,
. aij ! 2, 3 4 .
-! . ;
-+ .
28
4 ! A B. ' A(M, N)
B(N) C(M), . -
n
c j = ∑a jk bk . .
k =1
29
4 ! , -
( !). ! +- * + ( ).
30
5 !
! # . . ( , -
* # # ! # ., ! +*
! (-1) *. :
-– -
! # . *;
-.
2.6. , ! $!
1.! ! -#
( ).
2.0 ! + , !:
a);
58
b)# In.txt #
! +* Out.txt;
c);
d)Out.txt !
, # !
;
e), ! ! -
* ;
f)! !-
+
Out.txt ! .
1.0 ! .
2., , .
3.% ! .
4.' , .
5.6 ( ),
+ Agrapher.
6.2-# .
7..
8.! Out.txt.
' * ! ! .
% 12.
(Array – ).
|
, !$ |
# |
|
|
|
|
|
Size(Array) |
< , .- |
|
|
Array. |
. |
||
|
|||
|
|
|
|
|
< - ! |
' dim = 1 - - |
|
Size(Array,dim) |
, |
||
! . |
|||
|
|
dim = 2 – . |
|
|
< |
! +* - |
|
|
|
||
Shape(Array) |
|
||
Array ( |
|||
|
+ . |
||
|
– 2) |
||
|
|
||
|
|
|
59
|
|
|
% 13. |
|
0 : |
|
|
||
|
|
|
||
|
. & |
, !$ |
||
|
|
|
||
' |
MA – M × N |
MC – |
||
MC = Matmul(MA,MB) |
MB – |
N × P |
M × P |
|
|
|
|
|
|
4 |
MA – |
M × N |
V2 – M |
|
V2 = Matmul(MA,V1) |
V1 – N . |
. |
||
|
|
|
|
|
% |
MA – |
M × N |
MB – |
|
MB=Transpose(MA) |
N × M |
|||
|
|
|||
|
|
|
|
|
C |
V1, V2 – - |
S – ( ) |
||
S=Dot_product(V1,V2) |
||||
|
|
|||
|
|
|
||
6 # |
# M1 – * - |
|||
– |
||||
Call Random_number(M1) |
||||
[0; 1] |
|
|
||
|
|
|
||
|
|
|
|
! "
1.–
,
3.
2.' !
+* Interface.
3.( + – %
% .
4.– . , .
5.8 – ! , -
! .
6.! + +* +
( Intent(Out))
. / # #
! +, .
7./ # ! # -
!. / ,
! ! , - + . # ! # -
, *.
8.8 ! !
Intent.
# 1 ( )
! %: ! N #
. * .
60
! : +, ! 5
# . * 10 ..
1
Real Function Primer(Array,N)
Integer, Intent(In) :: N
Real, Intent(In), Dimension(1:N):: Array
Integer Len !
Len = Size(Array)
... ! , %
If(N>0)Primer=sum(Array)/N !
End Function Primer
Program Main ! 8 – Interface %
Implicit None
Interface
Real Function Primer(Array, N)
Integer,Intent(In) :: N Real,Intent(In),Dimension(:) :: Array End Function Primer
End Interface
Real Result
Real Dimension(1:10) :: Mas
... !
Result=Primer(Mas(6:10),5) ! : Mas,5-%
... !
End Program Main
1 Out.txt
Исходный массив
2.75 -12.88 0.12 -0.09 99.55
33.771.11 -4.66 3.00 2.99
Среднее арифметическое 5 последних элементов
5.923
# 2 (&)
!: ! +
. .
!: ! , -
! # + . ! #
.
2
( ,
.
61
Subroutine MaxAbs(Array, eLem, Num)
Implicit none Real,intent(in),dimension(:)::Array !
Real,intent(out)::eLem ! : max
Integer,intent(out)::Num ! : max
Integer Len !
Len = Size(Array)
... ! ,
eLem = ... !
Num = ... !
End Subroutine MaxAbs
Program Sub1 ! 5. 9$ 6 8. !.
Implicit none
Interface |
! $ |
||||
Subroutine MaxAbs(Array, eLem, Num) |
|||||
Implicit none |
|
|
|
||
Real,intent(in),dimension(:)::Array ! |
|||||
Real,intent(out)::eLem |
! : max |
||||
Integer,intent(out)::Num ! : max |
|||||
End Subroutine MaxAbs |
|
|
|||
End |
Interface |
|
|
|
|
Real,dimension(1:12)::B |
|
|
|||
Real,dimension(1:10)::C |
|
|
|||
Real MaxB, MaxC |
! max !,C |
||||
|
Integer NumB, NumC ! |
||||
|
... |
! % B |
|||
Call MaxAbs(B, MaxB, NumB) |
|
||||
|
... |
! % NumB, MaxB |
|||
|
... |
! % C |
|||
Call MaxAbs(C, MaxC, NumC) |
|
||||
|
... |
! % NumC, MaxC |
|||
End Program Sub1 |
|
|
|
||
Sub1 |
|
||||
Массив В |
|
|
|
|
|
1.0 |
-4.0 |
6.0 |
20.0 |
45.0 |
-71.0 |
4.0 |
-17.0 |
.0 |
.0 |
.0 |
11.0 |
max по модулю элемент |
-71.0 его номер |
6 в массиве B |
|||
Массив С |
|
|
|
|
|
-122.0 |
.0 |
45.0 |
71.0 |
4.0 |
-17.0 |
.0 |
.0 |
.0 |
11.0 |
|
|
max по модулю элемент -122.0 его номер |
1 в массиве C |