Created
March 11, 2010 01:50
-
-
Save natebenes/328710 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SUBROUTINE quadraticFormula(a,b,c,root1,root2,success) | |
IMPLICIT NONE | |
! Programmer: Nate Benes | |
! Purpose: Subroutine to calculate the real roots of a function | |
REAL, INTENT(IN) :: a,b,c ! Store the inputs of the function | |
REAL, INTENT(OUT) :: root1, root2 ! Store the outputs of the function | |
LOGICAL, INTENT(OUT) :: success ! variable to indicate whether we can find the root | |
REAL :: discriminant | |
discriminant = b**2-4*a*c | |
! Do some basic validation | |
IF((a == 0) .OR. (discriminant < 0)) THEN ! We can't solve this function | |
success = .FALSE. | |
WRITE(*,*) "Program either has complex roots or is not quadratic." | |
ELSE | |
root1 = (-b + SQRT(discriminant))*0.5/a | |
root2 = (-b - SQRT(discriminant))*0.5/a | |
END IF | |
END SUBROUTINE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment