5 REM quadratic equation solver
7  'by M.Merryfield; sept 1990
8 'public domain
10 REM input A, B and C
20 CLS
30 PRINT"    To solve a QUADRATIC EQUATION"
40 PRINT
50 PRINT"            of the form :-"
60 PRINT
70 PRINT"              ax^2+bx+c=0"
80 PRINT
90 INPUT"     Enter the values of a,b and c            (separated by a comma) ",A,B,C
100 PRINT
110 PRINT "        ";A;"x^2 X";B;"x X";C;"=0"
120 PRINT
130 REM checks for zero value variables and deal accordingly
140 IF A<>0 THEN 250
150 IF B<>0 THEN 210
160 IF C<>0 THEN 190
170 PRINT" The equation is of a curve, overlaying the X axis,providing an infinite number of values for X."
180 GOTO 620
190 PRINT" The equation is of the form c=y,         i.e. a horizontal straight line where there is no value of X"
200 GOTO 620
210 PRINT" This provides a linear equation of the form bx+c=0."
220 X=(-C/B)
230 GOSUB 680
240 GOTO 620
250 IF C<>0 THEN 350
260 IF B<>0 THEN 310
270 PRINT" This gives an equation of the form        ax^2=0"
280 X=0
290 GOSUB 680
300 GOTO 620
310 PRINT" This gives an equation of the form       ax^2+bx=0. If we divide by x we get     ax+b=0."
320 X=(-B/A)
330 GOSUB 680
340 GOTO 620
350 REM check if roots are REAL,COINCIDENT or COMPLEX
360 IF B^2 <> 4*A*C THEN 390
370 PRINT " The root is COINCIDENT,providing only 1 solution."
380 GOTO 410
390 IF B^2 < 4*A*C THEN 520
400 PRINT "The root is REAL,providing 2 solutions."
410 REM solve quadratic equation
420 X=(-B+SQR((B^2)-(4*A*C)))/(2*A)
430 X1=(-B-SQR((B^2)-(4*A*C)))/(2*A)
440 REM print quadratic solution
450 GOSUB 680
460 IF X=Y THEN 620
470 PRINT
480 PRINT"            OR"
490 PRINT
500 PRINT"       ";X1
510 GOTO 620
520 REM imaginary root
530 PRINT"   The root is IMAGINARY,so the solution must include a COMPLEX number."
540 PRINT
550 REM  imaginary solution
560 D=ABS(B^2-(4*A*C))
570 I=(SQR (D))/(2*A)
580 R=-B/(2*A)
590 PRINT"   X=";R;"+j";I;"   OR"
600 PRINT
610 PRINT"   X=";R;"-j";I
620 REM rerun draw graph or end
630 PRINT
640 PRINT"        Select option:                     1. Display graph.                       2. Solve another equation.              3. Exit program."
650 i$=INKEY$:IF i$="" THEN 650
660 i=VAL(i$):IF i<1 OR i>3 THEN 650
670 IF i=1 THEN 720 ELSE IF i=2 THEN 10 ELSE END
680 REM print out X routine
690 PRINT
700 PRINT"   The solution is ";X
710 RETURN
720 REM draw axes
730 CLS
740 ORIGIN 320,210
750 PLOT -320,0,1
760 DRAW 320,0
770 PLOT 0,-190
780 DRAW 0,190
790 REM plot graph
800 FOR X=-8 TO 8 STEP 0.04
810 Y=A*X^2+B*X+C
820 PLOT 40*X,4*Y,2
830 NEXT
840 LOCATE 1,25
850 INPUT " Do you wish to solve another? (Y/N)";Q$
860 IF Q$="Y" OR Q$="y" THEN 10
870 END