Basic_comphy_ch3

Basic_comphy_ch3 - Ch. 3 Fortran 90: Selective &...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
    1 Ch. 3 Fortran 90: Selective & Repetitive executions References: 1. T.M.R. Ellis et al., “ Fortran 90 programming” , Chs. 5, 6 2. L. Nyhoff & S. Leestma, “ Introduction to FORTRAN 90” , Ch. 3, 4
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    2 Outline 3.1 Selective execution 3.2 Repetitive execution
Background image of page 2
    3 3.1 Selective execution Decision-making How would I spend this Sunday? If my wife and son don't complaint, then I will go back to office alone :-) but if they complaint, then I will stay home :-( [. ...what next is usually not my decision!] but if only my son complaints, then I will ask whether he wants to go with me:  If yes, then I will go back to office with my son :-| If no, then I will stay home :-( [. ..what next is usually not my decision!] but if only my wife complaints, then I will ask whether she wants to go with me: If yes, then I will go back to office with my wife and son :-| If no, then I will go back to office alone anyway ;-)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    4 Logical expressions * We see in the previous example that each decision depends upon whether some criterion is true or false . * An expression which can take one of these two values (true or false) is called a logical expression . Logical values Example: x < 3 is a logical expression if x = 2 , the logical expression x < 3 is true. if x = 4 , the logical expression x < 3 is false. relational operator * In Fortran, the logical values are given by: .TRUE. . FALSE.
Background image of page 4
    5 * Fortran provides the following 6 relational operators : Symbol Meaning < or .LT. Is less than > or .GT. Is greater than == or .EQ. Is equal to <= or .LE. Is less than or equal to >= or .GE. Is greater than or equal to /= or .NE. Is not equal to expression 1 relational-operator expression 2 Usage: * expression 1 & expression 2 must be both arithmetic or both be strings * All arithmetic operators have a higher priority than any relational operator All relational operators have equal priority
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    6 Example: For the expression b**2 >= 4*a*c , b**2 and 4*a*c are evaluated before >= is evaluated Example: The following expressions give the same results b**2 >= 4*a*c b**2 – 4*a*c >= 0 4*a*c <= b**2 4*a*c – b**2 <= 0 Example: If a=2 , b=3 , c=1 , then the outcome of ( b**2 >= 4*a*c ) is .TRUE. If a=3 , b=1 , c=1 , then the outcome of ( b**2 >= 4*a*c ) is .FALSE. Remark : The 6 relational operators can also be used to compare character strings. But we shall not discuss this issue. (see, e.g., Sec. 5.5 of Ellis et al.)
Background image of page 6
  7 Question: How to represent the comparisons x < y < z in Fortran? Note that “ x < y < is equivalent to “ x < y and y < z (x < y).AND.(y < z) convert to Fortran syntax Logical operator * Fortran provides the following 5 logical operators : Operator Meaning .NOT. Negation .AND. Conjunction .OR. Disjunction . EQV. Equivalent .NEQV. Not equivalent
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 38

Basic_comphy_ch3 - Ch. 3 Fortran 90: Selective &amp;...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online