Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Современный Фортран_учебник

.pdf
Скачиваний:
31
Добавлен:
23.03.2015
Размер:
1.61 Mб
Скачать

112

7.

+ 3 !+

# # + # . #

[2]. 4 –

! , . 4 # + -

! + . " +

# ( + .)

* ( + ). --90 : –

, ! – % ,

.. # ,

max, min… + , +* .

# !

. ' - + # #, d .

 

 

 

113

 

 

7.1. 7

 

 

 

% 37.

 

 

 

 

 

 

 

! % !

 

 

max(a1,a2,..)

" : max(-8.3,6.0,2.0)=6.0;

 

! , *.

 

 

min(a1,a2,..)

" : min(-8.0,6.0,2.0) = –8.0;

 

! , *

 

 

abs(a)

| | – + .

 

 

mod(a,p)

& ;

 

mod(1, 2)=1;

mod(18,2)=0

 

 

int(a)

< ! ; int(-5.7) = –5; int(0.9)=0

 

 

nint(a)

2 ( ):

 

nint(-5.7) = –6; nint(0.9)=1

 

 

 

sign(a,b)

8 +

:

 

sign(1.0,-1.0E-25) = –1.0

 

 

sqrt(x)

/ ! ( ≥ 0)

 

 

exp(x)

$ x

log(x)

! lnx (x>0)

log10(x)

lgx (x>0)

 

 

 

 

sin(x),cos(x)

sin x

cos x

– #,

tan(x)

tg x

 

 

cotan(x)

ctg x

 

 

 

 

 

sind(x)

Sinx

– #,

cosd(x)

Cosx

 

 

tand(x)

Tgx

 

 

cotand(x)

ctgx

 

 

 

 

asin(x)

arcsinx (|x|<1.0). ! – #. (-π/2<asin(x)<π/2)

 

 

acos(x)

arccosx (|x|<1.0). ! – #. (0<acos(x)<π)

 

 

atan(x)

arctgx. ! – #. (π/2<atan(x)<π/2)

sinh(x)

 

 

 

cosh(x)

shx, chx, thx - , ,

tanh(x)

 

 

 

 

 

 

 

7.2.

– «*». -

# , - ! 0 (. ) !

. 3 :

1.Array – ;

2.Dim - * , : − Dim , ! – (0 );

114

Dim , +* !. ( # # ! – ;

3. Mask Array . / !:

+ # «array=»,« mask=» « dim=»;

– + «array=»,

«mask=», «dim=» .

: Array Mask – . ( -

# . , # .. - Mask + ,

! !, ,

Array=Ar + mask=Ar>0 Array=Ar(1:3) mask=Ar>0.

, '

#, # ,

* :

Real,dimension(1:7):: Ar

% 38.* #

7 Ar=[ 2.1, -0.7, 0.0, 17., -12., 0.4, -35.5]

4 1

2

3 4

5

6

7

, Sum, Product, MinVal, MaxVal

5 ! # , - # #, $ ( ! -). %, 72 dim !

! dim=1 – ! –

, . 8 dim # #

, !

!. 5 % + :

Real,dimension(1:5):: Ar; Real Value Value = Sum(array[, dim][, mask]) !

Value = Product(array[,dim][,mask]) !

Value = MinVal(array[,dim] [,mask]) !

Value = MaxVal(array[, dim][,mask]) !

1.0 ! ! . Ar

Real Zmin

( MinVal: Zmin=MinVal(Ar,1,Ar>0) – , -

! # #;

115

Zmin=MinVal(Ar,mask=Ar>0) – * 72 dim- . # ! mask 73, .

! +* # #

.

!: Zmin = 0.4

2.0 ! . Ar [0.1, 17.6]

Real Zmax; Zmax=MaxVal(Ar, mask=0.1<=Ar.and.Ar<=17.6)

!: Zmax = 17.0

3.0 ! # . Ar(1:7:3)

Real SumQu; SumQu=Sum(Ar(1:7:3)**2, mask=Ar(1:7:3)>0)

!: SumQu = Ar(1)2 + Ar(4)2 = 2.12 + 172 = 293.41

4.0 # . Ar(3:7)

Real Prod; Prod=Product(abs(Ar(3:7)),mask=Ar(3:7)/=0)

!:

Prod = Ar(4) * Ar(5) * Ar(6)* Ar(7) = 17.0*12.0*0.4*35.5 = 2896.8

!, , , ! + , +

. + ! Mask, size(Array)size(Mask) : − ,

Su=Sum(Array =Ar(1:3),mask=Ar>0)

Su=Sum(Array=Ar(1:N), mask=Ar>0)- $

-при N=7 !

-N<7 !

-! : Su=Sum(Array =Ar(1:N), mask=Ar(1:N)>0)

Any, all–

* + : Any(mask) – ! «true», ! . -

mask; , . . ; All(mask) – ! «true», . +

mask; , . . .

1.1 ! Ar ., + ! 30 ?

Logical L1; L1=Any(abs(Ar)>30)

!: L1 = .true. |-35.5|>30 (

if(Any(abs(Ar)>30))print *,’ Ar > 30 presents

2.. ! !?

Logical L2

L2 = All(Ar(5:7)<0) ! ! : L2=.false.

( :

if(.not.All(Ar(5:7)<0))print *,’not all 8r(5:7)< 0’

116

, Count

* – ., mask int=count(mask). mask.

0 . ,r, + ! # 11.

Integer K11; K11 = Count(abs(Ar)>11)

!: K11=3 – .: |Ar(4)|>11, |Ar(5)|>11, |Ar(7)|>11

!:

Mask + -

,

all, any, count;

dim # # , !

!.

MaxLoc MinLoc

MaxLoc, MinLoc . +

+ # .

Integer,dimension(1:1):: Num Num=MaxLoc(array[,mask])! Num(1)-

Num=MinLoc(array[,mask])! Num(1)-

( MaxLoc, MinLoc * + -

! (MinLoc)

! (MaxLoc) . Array = Ar.

1.0 ! . Ar.

Integer,dimension(1:1):: Num; Integer N Num=MaxLoc(Ar); N = Num(1)

" MaxLoc(Ar) ! + +

# , :

N=Sum(MaxLoc(Ar))

!: N = 4 – ! . Ar(4) = 17.0

2.0 ! ! . Ar.

Integer,dimension(1:1)::Num; Integer N Num=MinLoc(Ar,mask=Ar>0); N=Num(1)

N=Sum(MinLoc(Ar,mask=Ar>0))

N=Sum(MinLoc(Ar,1,Ar>0))

!: N=6 ! ! . Ar(6)=0.4

, '

# , + array=Matr,

# Num ! #

.: Integer,dimension(1:2)::Num

Real,dimension(1:2,1:5) :: Matr

117

% 39. * #

 

 

1

2

3

4

5

!

1

-11

–12.

–13.

–14.

–15.

( Matr)

2

-21

–22.

–23.

–24.

0.

6 #, , dim,

! , , #

. ( dim -

! ! {1,2}:

dim: * – , ;

dim =1: * – - , - ! ;

dim =2: * – - , -

! .

- + ! array:

Value = Sum(array[, dim][, mask]) !

Value = Product(array[,dim][,mask]) !

Value = MinVal(array[,dim] [,mask]) !

Value = MaxVal(array[, dim][,mask]) !

1.Matr ., ! # -20

Real S; S = MinVal(Matr, mask=Matr>-20)

8 dim . ! : S = -15.0

2.0 max . Matr ( - )

Real, dimension(1:5) S; S = MaxVal(Matr, dim=1)

! – - : S(1:5)= [ –11., –12., –13., –14., 0. ]

3.0 - . -

Matr, ! # –22.5

Real,dimension(1:2)S;S=Sum(Matr,dim=2,mask=Matr>-22.5)

! – - : S(1)=– 11. – 12. – 13. – 14. – 15.,

S(2)=21. – 22. + 0. => S(1:2)= [ – 65., – 43. ]

4.0 - - # . Matr .

Real, dimension(1:2) S S=product(Matr(:,1:5:2),2,mask=Matr(:,1:5:2)/=0)

! – - : S(1) = (-11)*(-13)*(-15) = –2145. S(2)=2 (-21)*(-23) = 483.

' # * +

:

118

any(mask[,dim]) – ! « », ! .-

mask, ! . ; all(mask[,dim]) – ! « », . -

mask, ! . .

8 Mask +

, .

1.1 ! Matr ., + +* 30?

Logical L; L=Any(abs(Matr)>30)

8 dim . ! – , L = .FALSE.

2.' Matr: ! . > (–1)?

Logical, dimension(1:2) L; L=Any(Matr>-1, dim=2)

! ( - ) L(1:2) =[.false.,.true. ]

3.& Matr: . !?

Logical, dimension(1:5) L; L=All(Matr<0, dim=1)

! – ( - )

L(1:5)=[.true.,.true.,.true.,.true., .false. ]

, * -

– ., +* # + mask

Count(mask[,dim])

1.' ! ! # . Matr.

Integer K; K=Count(Matr<0)

8 dim . ! – K=9

2.' ! ! . Matr

Integer,dimension(1:2)K; K= Count(Matr<0, dim=2)

! – ( - ) K(1:2)= [5, 4]

MinLoc MaxLoc

* + # -

, .. Num = MaxLoc(array[,mask]) !

Num = MinLoc(array[,mask]) !

1.0 ! . Matr

Integer, dimension(1:2):: Num Num = MaxLoc(Matr)

!: Num= [ 2, 5 ] Matr(2,5) = 0.

2.0 ! ! . Matr

Integer, dimension(1:2):: Num Num = MaxLoc(Matr, Matr<0)

!: Num = [ 1, 1 ] Matr(1, 1) = –11.

3.0 max + . Matr

119

Integer, dimension(1:1):: Num

! ( )

Num = MaxLoc(abs(Matr(1,1:5))); N = Num(1)

!: Num(1) = 5; N = 5 Matr(1, 5) = –15.

4.0 min . > (-20) Matr

Integer, dimension(1:1):: Num

! $ ( )

Num=MinLoc(Matr(1:2,3),Matr(1:2,3)>-20));

N=Num(1)

!: Num=[ 1 ]; N = 1 Matr(1, 3) = –13.

: -95 ! -

dim, -90.

8.

, ' &

% ,

C , # (plain- ), . .

, ! # # 3. :

Developer Studio, Visual Studio Windows;

FAR ( Windows/ANSI DOS/ASCII);

MULTI-EDIT 8.0 Windows DOS;

Windows;

Geany Linux .

– ! . & 3, +

– , . #. ' -90 ! .f90 (

-03 – .f03). Windows, ! + ,

+ ANSI, Windows.

, !:

DOS ! ! ASCII;

Windows ! + ANSI ASCII

! ASCII * !+.

/ ASCII ANSI Windows +,

* write(*,*) ’waiting for data’ ,

. +, .-

* write(*,*) ’ -

, ASCII,

! Windows. 1 Windows,

. $ $ ( ANSI – ).

:

1., ., ! - , , -

«!» ! «Input», ! ! -

far ;

120

2.! +* ! -

DevStudio ! word far.

1

+ +* # :

+ ;

! + ! #;

+ # , !- + + .

, -

. / , ,

– -

<Enter>. -

, # + «;».

% ( ) + -

. / , +* !,

* # , ,

C1: DO ! $ «C1:» do

if( 1 ) cycle c1 ! C1 if( 2 ) exit c1 !

enddo

ENDDO C1 ! $ «C1»

0 ! ! -

: write(*,23) ‘ ’; write(*,23) ‘ ’; 23 format(2x,a)

! -

#. & # «goto

» , # +. 0 -

# # ! ! + goto.

8.1. # Agrapher &

0 :

.

!

. jpg-

+* # # #.

' , ! #,

# # :

Agrapher, http://www.alentum.com – , -

; +.

Agrapher Windows – +

. ! +. & Agrapher !+ .

121

2 Grapher - , ; , -

! +* , ! .

! Agrapher:

1.Y(X);

2.X(Y);

3.X(t),Y(t), , ;

4.X,Y, Agrapher;

5., , -

# – ! # (>0);

6.– + | $ ( -

txt +);

7.! ( , , ).

:

! , ;

! , ;

! , * ! .

0 # ! ! +. 1 ! , -

. Agrapher , -

, . ! # .:

+ « », ! ,

« » ! X Y;

!

# « » , . !

;

+ * ;

! -

! , #.

% 40.

' !

. " "

' ! 6, ! Y (0,b).

 

 

 

 

 

 

y=b

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

' ! Y, ! X (a,0).

 

 

 

 

 

 

x=a

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

' # (x1,y1) α 6.

(y-y1) = k(x-x1)

 

 

k = tg α

' ! Y (0,b) α 6.

 

 

y = kx+b

 

 

0 α<π

 

 

 

 

 

 

 

 

 

 

 

 

α π/2

' # (0,0) α 6.

 

 

 

y = kx

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

' # (x1,y1) (x2,y2),

 

 

 

 

 

y y1

 

=

 

x x1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

x1x2, y1y2.

 

 

 

 

y2 y1

x2

x1

 

 

 

 

 

 

 

 

 

 

 

' ! 6 (a,0), ! Y (0,b)

 

x

+

y

= 1 y =

 

 

 

b

x + b

( #).

 

 

 

 

 

 

a b

 

 

 

 

 

 

 

 

a