180 likes | 368 Views
AME 150 L. Review for Exam #1. Student Professional Societies. ASME - American Society of Mechanical Engineers Freshman Free - (but no magazine) Special Student rate ($10) get publications SAE - Society of Automotive Engineers Student Dues $10 (OHE 430)
E N D
AME 150 L Review for Exam #1 AME 150 L
Student Professional Societies ASME - American Society of Mechanical Engineers • Freshman Free - (but no magazine) • Special Student rate ($10) get publications SAE - Society of Automotive Engineers • Student Dues $10 (OHE 430) AIAA - American Institute of Aeronautics & Astronautics • Student Membership $7.50 (rest of year) Professional Society Membership is valuable! AME 150 L
HW5 • http://megakap.usc.edu/AME150/AME150L_HW.htm Write a Fortran program to read a number from the keyboard and write out the number, its square root, and its cube root to the display. If the given number is negative, the program should output the character string "Imaginary" instead of the square root. Submit the source with tag HW5. AME 150 L
PROGRAM hw5 IMPLICIT none REAL :: x, sqx, cubx WRITE(*,*)"Enter x=" READ(*,*)x IF (X > 0) THEN sqx = SQRT(x) cubx = x**(1./3.) WRITE (*,*)x,sqx,cubx AME 150 L
ELSE cubx=-ABS(x)**(1./3.) WRITE(*,*)x," Imaginary, " ,cubx END IF stop END PROGRAM hw5 AME 150 L
Cube Roots • Issues • 1) Argument of **(1/3.) must be positive • 2) Sign of result is sign of argument • One line definition cubert=sign(1.,x)*abs(x)**0.33333333 • NOTE: need 8 3's for full accuracy AME 150 L
Round-off Errors (revisited) • F*(1/F) should always be close to 1 • Optimizing compilers realize that there is a divide and multiply, and make the result=1 (independent of round-off) • Ordinary compilers cannot • [Examples on Intel and Sparc] AME 150 L
Logical Operators LOGICAL,parameter :: T=.TRUE., F=.FALSE. a ba.AND.ba.OR.ba.EQV.ba.NEQV.b F F F F T F F T F T F T T F F T F T T T T T T F Also B: 38-40, D: 132-137 AME 150 L
Trigonometry • Fortran default trig assumes the argument is in radians (p radians = 180°) • Conversion factors • p = 3.14159274 (on Sparc) [3.1415926535897931] • 1 radian= 180/ p = 57.29578... [degrees/radian] • 1 degree=p /180 =0.01745329... [radians/degree] • Pi = 4.0 * ATAN (1.0) AME 150 L
Useful Parameters REAL, parameter :: pi = 3.14159274, pi_over_two=pi/2. REAL, parameter :: rad_to_deg=180./pi, deg_to_rad=pi/180. REAL (kind=8), parameter :: pi_long=3.1415926535897931d0 [I will keep these definitions on a file in the "useful stuff" web page, adding to the file as appropriate] AME 150 L
What can he ask on the Quiz? • You'd be surprised! • Give Fortran Statements - Correct errors • Give Fortran data - evaluate results • Give Algebra - write Fortran • Give Fortran - What is the algebra? • .True. or .False. AME 150 L
Give Fortran Statements - Correct Errors WRITE(*,*),Please enter a number=, READ(**)x**y INPLICIT NONE REAL ::: A=1.,b,c INTEGER :: I, J, K=3.0 sum = co+x(c1+x(c2+x(c3+x))) sum = co +c1*x + c2*x**2 + c3 x**3 AME 150 L
Give Fortran Programs Correct Errors Program TesT INTEGER :: I,j kl I=5; j=3.7 REAL :: x=2.5,y=-7 IMPLICIT none WRITE(*,*),I+J,Y**X PAUSE end proGRAM test AME 150 L
REAL:: X=8,Y=-5.,z=1.5,W W = X ** 1/3 W = (Y + K ) / j W = Y + K / z + i W = (Y + X ) / 2. * z INTEGER :: j=6, K=3,i=5,L L = i / K+2 L = i + j / K + 1 L = i ** K L = (i + K) /( j + 2) Give Fortran Data - Evaluate Results AME 150 L
(a+b)/(c+d**2) exp(-(u*u+v*v)/(4.*k*T)) 1.57e23 Give Algebra - Write Fortran AME 150 L
1+y/(1+y/(1+Y/x)) A**b**c 2**3**2=2**(3**2)=2**9=512 not (2**3)**2=8**2=64 Give Fortran - What is the Algebra? AME 150 L
How do you change the use of the hello.f90 program to write its output in the file hello.txt instead of on the display? 1) Keep the hello.f90 the same as in class 2) Compile it as follows f90 hello.f90 -o hello 3) hello >hello.txt voila! Maybe some munix Questions AME 150 L
True or False? AME 150 L