SlideServe
Menu
Préférences
© SlideServe · v2026

Today’s Assignment

tori avatar
19 diapositives · 365 Views · Aug 23, 2014

This assignment involves creating a flowchart to evaluate the roots of a quadratic equation in the form of ax² + bx + c = 0, including both real and complex roots. It covers the quadratic formula r₁,₂ = (-b ± √(b² - 4ac)) / (2a) and distinguishes between real, distinct roots, real, repeated roots, and complex conjugate roots. Additionally, it includes a Fortran programming example that calculates friction factors using the appropriate formula based on the Reynolds number, demonstrating logical control in programming.

Today’s Assignment - slide 1
01 / 19Today’s Assignment
1 / 17

Télécharger la présentation

Today’s Assignment
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Today’s Assignment Construct A Flowchart To Evaluate The Roots Of A Quadratic Equation, Including Complex Roots • a x2 + b x + c = 0 • r1,2 = -b +- sqrt(b2 – 4ac) 2a • real, distinct • real, repeated • complex conjugate • special case when a = 0

  2. Quadratic Flowchart

  3. Quadratic Solver Flowchart START Enter a, b, c Calculate b2 – 4ac compare: b2 – 4ac < 0 > 0 = 0 CC roots real,repeated roots real, distinct roots R +- i I r1 r1, r2 End

  4. Scientific Programming Class 5

  5. Logical Variables • L1 = (logical expression) • L1, L2, L3 are either .TRUE. or .FALSE. • IMPLICIT NONE • INTEGER:: i, j, k, etc • REAL:: a1, a2, a3, etc • LOGICAL:: L1, L2, L3, etc

  6. Relational Operators • Relational Operators • == Equal To (Note doubling - ==) • /= Not Equal To • > Greater Than • >= Greater Than or Equal To • < Less Than • <= Less Than or Equal To • For comparing arithmetic operations, constants, variables or character strings.

  7. Combinational Operators • L1.AND.L2 • .TRUE. If both are .TRUE. • L1.OR.L2 • .TRUE. If either or both are .TRUE. • L1.EQV.L2 • .TRUE. If L1 & L2 are the same • L1.NEQV.L2 • .TRUE. If L1 & L2 are different • .NOT.L1 • Opposite L1 • For comparing logical statements

  8. Combinational Operators • Hierarchy of Operations • Arithmetic • Relational L to R • .NOT. • .AND. L to R • .OR. L to R • .EQV. & .NEQV. L to R • Use ( ) to control the order

  9. Block IF • IF (logical statement) THEN • Statement 1 • Statement 2 • ….. • END IF • Next line of code • …

  10. Block IF (cont.) • If (logical statement) is .TRUE., the program executes the block of code following the IF THEN statement • If (logical statement) is .FALSE., the program executes the code following the END IF statement

  11. ELSE & ELSE IF • IF (logical statement 1) THEN • Statement 1 • Statement 2 • ….. • ELSE IF (logical statement 2) THEN • Statement 1 • Statement 2 • …………………….More ELSE IF statements • ELSE • Statement 1 • Statement 2 • ….. • END IF • Next line of code • …

  12. ELSE & ELSE IF (cont.) • If (logical statement 1) is .TRUE., the program executes the block of code following the IF THEN statement and jumps to the statement following the END IF statement • If (logical statement 1) is .FALSE., the program jumps to the first ELSE IF statement and on, and on, and on….. • The last clause may be an ELSE statement without a logical statement

  13. Example: Moody Chart

  14. Example: Moody Chart • Laminar Flow: Re <= 2200 • f = 64/Re • Turbulent Flow: Re > 2200 • Colebrook Formula:

  15. Example: Moody Chart • Write, compile & run a Fortran program that calculates D-W friction factors for a pipe with inside diameter, D (in), roughness, e (mm), & Reynold’s Number, Re (dim). The program must use logic to control which friction factor formula to use in the calculation for f. • Use READ statements for the e, D & Re input so that the program can be used for any input.

  16. Example: Moody Chart • PROGRAM colebrook1 • !e = pipe roughness (mm) • !d = pipe inside diameter (in) • !relruff = relative roughness (dim) • !re = Reynolds Number (dim) • !f = Darcy-Weisbach Friction Factor (dim) • IMPLICIT NONE • REAL:: f, f0, f1, re, e, d, relruff • INTEGER:: k • WRITE(*,*)'Enter e in mm & D in inches' • READ(*,*) e, d • WRITE(*,*)'Pipe Roughness, e =',e,'mm ','Pipe Diameter, D =',d,'inches' • relruff = e/(d*25.4) • WRITE(*,*)'relative roughness =', relruff • WRITE(*,*)'Enter Reynolds No' • DO k = 1, 11 • READ(*,*) re • IF (re<=2200.) THEN • f = 64./re • WRITE(*,*)'For Reynolds No =',re,'Darcy-Weisbach Friction Factor =',f • ELSE • f0 = .25*((LOG10((relruff/3.7)+(5.74/(re**.9))))**(-2)) • f1 = (-2.)*LOG10(((relruff/3.7)+(2.51/(re*(f0**.5))))) • f = (1./f1)**2 • WRITE(*,*)'For Reynolds No =',re,'Darcy-Weisbach Friction Factor =',f • END IF • END DO • END

  17. Example: Moody Chart c:\FortranSources>colebrook1 Enter e in mm & D in inches .26,2.067 Pipe Roughness, e = 0.2600000 mm Pipe Diameter, D = 2.067000 inches relative roughness = 4.9522114E-03 Enter Reynolds No 500 For Reynolds No = 500.0000 Darcy-Weisbach Friction Factor = 0.1280000 1000 For Reynolds No = 1000.000 Darcy-Weisbach Friction Factor = 6.4000003E-02 1500 For Reynolds No = 1500.000 Darcy-Weisbach Friction Factor = 4.2666666E-02 2000 For Reynolds No = 2000.000 Darcy-Weisbach Friction Factor = 3.2000002E-02 2200 For Reynolds No = 2200.000 Darcy-Weisbach Friction Factor = 2.9090909E-02 3000 For Reynolds No = 3000.000 Darcy-Weisbach Friction Factor = 4.7594767E-02 10000 For Reynolds No = 10000.00 Darcy-Weisbach Friction Factor = 3.7515681E-02

  18. Example: Moody Chart

  19. Assignment: 2nd Order Solver • Write, compile & run a Fortran program that uses the quadratic formula to determine the roots of the 2nd order equation: • a x2 + b x + c = 0 • The program must be able to handle all cases: • real distinct roots • real, repeated roots • complex conjugate roots • the special case where a = 0. • Use READ statements for the a, b, & c input so that the program can be used repeatedly without restarting.