Roots of a quadratic function: Difference between revisions

no edit summary
No edit summary
Line 1,241:
Equation(a=1.0, b=1.0, c=1.0)
X1 = -0.5 + 0.8660254037844386i, X2 = -0.5 + -0.8660254037844386i</pre>
 
=={{header|lambdatalk}}==
<lang scheme>
{def equation
{def equation.disp
{lambda {:x1 :x2 :txt}
{table {@ style="background:#ffa"}
{tr {td :txt: }}
{tr {td x1 = :x1 }}
{tr {td x2 = :x2 }} } }}
 
{lambda {:a :b :c}
{b equation :a*x{sup 2}+:b*x+:c=0}
{{lambda {:a' :b' :d}
{if {> :d 0}
then {{lambda {:b' :d'}
{equation.disp {+ :b' :d'} {- :b' :d'} 2 real roots}
} :b' {/ {sqrt :d} :a'}}
else {if {< :d 0}
then {{lambda {:b' :d'}
{equation.disp [:b',:d'] [:b',-:d'] 2 complex roots}
} :b' {/ {sqrt {- :d}} :a'} }
else {equation.disp :b' :b' one real double root}
}}
} {* 2 :a} {/ {- :b} {* 2 :a}} {- {* :b :b} {* 4 :a :c}} }
}}
 
equation 1*x2+1*x+-1=0
2 real roots:
x1 = 0.6180339887498949
x2 = -1.618033988749895
equation 1*x2+1*x+1=0
2 complex roots:
x1 = [-0.5,0.8660254037844386]
x2 = [-0.5,-0.8660254037844386]
 
equation 1*x2+-2*x+1=0
one real double root:
x1 = 1
x2 = 1
</lang>
 
=={{header|Liberty BASIC}}==