To solve quadratic equations you need to know the solution formula.
Arrange the equation like this
a,b,c are parameters for your equations.
a*
x^2+
b*
x+
c=0 - Pull out a
a*(
x^2+(
b/a)*
x+(
c/a))=0
Convert the
x^2+
(b/a)*
x to a complete square:
(
x^2+
(b/a)*
x+
(b^2/4a^2))=(x+
b/2a)^2
So
x^2+
(b/a)*
x can be turned into the line above like this:
(
x^2+
(b/a)*
x+
(b/2a)^2) -
(b/2a)^2so it's gona be:
(
x+
(b/a))^2 -
(b/2a)^2(
x+
(b/a))^2-
(b^2/4a^2)I hope you understand what (a+b)^2 is
![:D](https://www.hard-light.net/forums/Smileys/HLP/biggrin.gif)
Let's put that back into the original equation:
a*[(
x+
(b/a))^2 -
(b^2/4a^2) +
(c/a)] = 0
-
(b^2/4a^2)+
(c/a) can be simplified:
-
[(b^2-4ac)/4a^2]Put that back into the original:
a*[(
x+
(b/2a))^2 - (
(b^2-4ac)/4a^2)] = 0
If
(b^2-4ac)<0 then we multply a positive number with a so the result can't be 0.
So
(b^2-4ac)>=0 is the only case when there can be a solution to the equation.
This is also called as the second degree equation's discriminant - this determines how many solutions the equation has.
If
(b^2-4ac) is bigger than 0 we can have its square root:
a*[
x^2-SQR{
(b^2-4ac)}/
2a]
What's nice about this?
It corresponds with the a^2-b^2=(a+b)*(a-b) formula:
a*[
x+
(b/2a)+SQR{
b^2-4ac}/
2a]*[
x+
(b/2a)-SQR{
b^2-4ac}/
2a]
The result will be 0 if either of the parts are equal to 0 since its a multyplication.
a can't be 0 since then it would be a first degree equation.
So we have 2 solutions:
x1+
b/2a+SQR{
b^2-4ac}/
2a=0
and
x2+
b/2a-SQR{
b^2-4ac}/
2a=0
So
x would be:
x1=(-b+SQR{b^2-4ac})/2a
x2=(-b-SQR{b^2-4ac})/2a