quadratic equation contd.

HI; FOR TOM L. AND MCLURED WHO BOTH ANSWERED MY PLEA FOR HELP WITH SUBROUTINE. THE PROGRAM BY TOM WORKS VERY WELL,HOWEVER MOST OF THE PROBLEMS IN MATH BOOKS GIVE ANSWERS USING IMAGINARY ROOTS. IS THERE ANYWAY TO MODIFY OR ADD TO QUADRATIC SOLUTION SUB.WHICH DOES NOT GIVE THE ANSWERS TO THE SPECIFIC PROBLEMS WHICH USE IMAGINARY ROOTS. I AM NOT A MATHEMETICIAN BUT INTERESTED IN THE SUBJECT,SO THEREFORE I HAVE NO IDEA HOW TO EVEN GO ABOUT THIS ,BUT I AM LEARNING FROM YOU PEOPLE.HOPEFULLY THIS WILL PIQUE YOUR INTEREST....REGARDS,JOSEPH DOBASH

Comments

Quadratic Eq cont.

Certainly there is. I anticipated your request so I used SELECT CASE rather than IF-THEN-ELSE so that the three possibilites (two real roots, one real root, two imaginary roots) would be more easily seen.


DO
INPUT a,b,c
CALL quadratic(x1,x2,a,b,c)
IF x1 <> x2 AND x2 <> -MAXNUM THEN
PRINT "Roots are: "; x1;" and ";x2
ELSEIF x1 = x2 THEN
PRINT "Single Root is: "; x1
ELSE
PRINT "Imaginary roots are : "; -b/(2*a);"+";x1;"i and ";-b/(2*a);"-";x1;"i"
END IF
LOOP

END

EXTERNAL SUB Quadratic(x1,x2,a,b,c)
LET discr = b^2-4*a*c
SELECT CASE discr
CASE IS > 0 ! Two real roots
LET x1 = (-b + SQR(discr)) / (2*a)
LET x2 = (-b - SQR(discr)) / (2*a)
CASE IS = 0 ! One real root
LET x1, x2 = -b / (2*a)
CASE ELSE ! Two imaginary roots
LET x1 = SQR(-discr) / (2*a)
LET x2 = -MAXNUM
END SELECT
END SUB

quadratic equation

joseph dobash for tom l. the revised program you wrote for the quadratic, and which contains solutions for both real and imaginary roots works very well tom. I am most grateful for your kindness and help.thank you again. joseph dobash for tom l.