Quadratic equation in Logo

Example for versions UCBLogo 6.0

This example defines function quadraticwhich accepts coefficients of quadratic equation and prints the roots. Usage is quadratic 1 -2 1.

to quadratic :A :B :C
   if :A = 0 [(print [Not a quadratic equation.])
              stop
             ]
   make "D :B*:B - 4*:A*:C
   if :D = 0 [(print [x = ] -:B/2/:A)
              stop
             ]
   if :D > 0 [(print [x1 = ] (-:B+sqrt :D)/2/:A)
              (print [x2 = ] (-:B-sqrt :D)/2/:A)
              stop
             ]
   (print [x1 = (] -:B/2/:A [,] (sqrt (-:D))/2/A [)])
   (print [x2 = (] -:B/2/:A [,] (-sqrt (-:D))/2/A [)])
end