FORTRAN 90 Lecture : Rafel Hekmat Hameed University of Babylon Subject : Fortran 90 College of Engineering Year : Second B.Sc Mechanical Engineering Dep. 1. INTRINSIC FUNCTIONS MATHEMATICAL FUNCTIONS Function ABS(x) SQRT(x) SIN(x) COS(x) TAN(x) ASIN(x) ACOS(x) ATAN(x SINH(x) COSH(x) TANH(x) EXP(x) LOG(x) LOG10(x) Meaning absolute value of x square root of x sine of x radian cosine of x radian tangent of x radian arc sine of x arc cosine of x arc tangent of x hyperbolic sine of x hyperbolic cosine of x hyperbolic tangent of x exp(x) natural logarithm of x Log10 base of 10 logarithm of x SOME cONVERSION FUNCTIONS Function INT(x) NINT(x) FLOOR(x) FRACTION(x) REAL(x) Meaning Arg. Type truncate to integer part x round nearest integer to x greatest integer less than or equal to x the fractional part of x convert x to REAL Examples INT(-3.5) -3 NINT(3.5) 4 NINT(-3.4) -3 ϭ REAL REAL REAL REAL INTEGER Return type INTEGER INTEGER INTEGER REAL REAL FLOOR(3.6) 3 FLOOR(-3.5) -4 FRACTION(12.3) 0.3 REAL(-10) -10.0 Other FUNCTIONS Function MAX(x1, x2, ..., xn) MIN(x1, x2,…, xn) MOD(x,y) Meaning maximum of x1, x2, ..., xn minimum of x1, x2,…, xn remainder x - INT(x/y)*y Examples Mod(2.2,2)= 2.2-int (2.2/2)*2= 2.2-1*2= 2.2-2=0.2 Example Write a program to calculate the area of circle PROGRAM circle_area IMPLICIT NONE !reads a value representing the radius of a circle, !then calculates and writes out the area of the circle. REAL :: radius, area REAL, PARAMETER :: pi=3.141592 READ (*,*) radius area = pi*radius*radius WRITE (*,*) area END PROGRAM circle_area Ϯ Example PROGRAM Test IMPLICIT NONE INTEGER, PARAMETER :: result = 42 ! Simple output statement... PRINT *, ’Hello world!’ PRINT *, ’The result is ’, result END PROGRAM Test E Exxaam mppllee Given base b and height h, the length of a special segment on a parabola can be computed as follows: ඥࢎ ࢈ ࢈ ࢎ ξࢎ ࢈ ࢍ ቆ ቇ ࢎ ࢈ Write a program to read the values of base and height, and use the above formula to compute the length of the parabola segment. Note that both base and height values must be positive. PROGRAM ParabolaLength IMPLICIT NONE REAL :: Height, Base, Length REAL :: temp, t WRITE(*,*) 'Height of a parabola : ' READ(*,*) Height WRITE(*,*) 'Base of a parabola : ' READ(*,*) Base ! ... temp and t are two temporary variables t = 2.0 * Height temp = SQRT(t**2 + Base**2) Length = temp + Base**2/t*LOG((t + temp)/Base) WRITE(*,*) WRITE(*,*) 'Height = ', Height WRITE(*,*) 'Base = ', Base WRITE(*,*) 'Length = ', Length END PROGRAM ParabolaLength input values for Height and Base are 100.0 and 78.5, respectively. The computed length is 266.149445. ϯ E Exxaam mppllee ((H H..W W)) Convert temperature at 30oC from Celsius to Fahrenheit . Note: Fo = Co*9/5+32 E Exxaam mppllee ((H H..W W)) Write a program to transforms the Cartesian coordinate (x,y) presentation to the polar coordinates (r, ). Use the definitions Sin = y/r , cos = x/r , r = (x2 + y2).5 ϰ