[- use Algebra::GenPage; use Algebra::SolverLib; use Algebra::HTML; use Enurl; -] [- $escmode = 0; sub graph_link { my ($a, $b, $c) = @_; my $encoded = enurl { 'a'=>$a, 'b'=>$b, 'c'=>$c }; return "\"; } sub reduce_fraction { my ($num, $denom) = @_; if( int($num) != $num || int($denom) != $denom ) { return "$num/$denom"; } if( (int( $num/$denom )) == ($num / $denom) ) { return $num / $denom; } my $n1 = $num < 0 ? -$num : $num; my $n2 = $denom < 0 ? -$denom : $denom; while( $n1 != $n2 ) { if( $n1 > $n2 ) { $n1 = $n1 % $n2; if( $n1 == 0 ) { $n1 = $n2; last; } } else { $n2 = $n2 % $n1; if( $n2 == 0 ) { $n2 = $n1; last; } } } return $num/$n1 . "/" . $denom/$n1; } sub signed { my $num = shift @_; return "+$num" if $num >= 0; return $num; # negative } sub sign { my $num = shift @_; return '+' if $num >= 0; return '-'; } sub term { my $num = shift @_; return $num + 2 - 1 - 1 if $num >= 0; return "($num)"; } $a = "$fdat{a}"; $b = "$fdat{b}"; $c = "$fdat{c}"; $a = 1 if $a eq ""; $b = 1 if $b eq ""; $c = 0 if $c eq ""; $first_sign = ($fdat{first_sign} eq '+') ? 1 : -1; $signed_b = $b * $first_sign; $second_sign = ($fdat{second_sign} eq '+') ? 1 : -1; $signed_c = $c * $second_sign; $discr = $b*$b-4*$a*$signed_c; $ac4=-4*$a*$c*$second_sign; if( $a != 0 ) { if( $discr > 0 ) { $x1 = (-$signed_b + sqrt( $discr ))/2/$a; $x2 = (-$signed_b - sqrt( $discr ))/2/$a; $solution = "$x1, $x2"; $factored = ($a != 1 ? $a : "") . "(x". signed(-$x1) .")(x". signed(-$x2) .")"; } elsif( $discr == 0 ) { $solution = -$signed_b/2/$a; $factored = ($a != 1 ? $a : "") . "(x". signed(-$solution) .")(x". signed(-$solution) .")"; } else { $solution = "no real solutions"; $factored = "Expression cannot be factored"; } &process_request( \%fdat, \%udat, "Solve Quadratic Equation $a"."x^2".signed($signed_b)."x".signed( $signed_c )." = 0" ); } else { $solution = "Sorry , the first coefficient is zero, which makes the equation not a quadratic equation."; $factored = "Expression cannot be factored"; } $escmode = 0; -] [+ make_page_header( "Quadratic Solver", "Algebra.Com", "Algebra", "Algebra Homework" ) +]
[NEW!]Practice with Quadratic Equations! Improve Your Test Scores!
[NEW!]Check out Word Problems involving Quadratics!
[+ lesson_link( "quadform" ) +]

Quick Answer

Actual Graph of y = [+ "$a"."x\2\" . sign( $signed_b ) . "$b"."x" . sign( $signed_c ) . "$c " +]
[+ graph_link( $a, $signed_b, $signed_c ) +]
See [+ lesson_link( "graphing" ) +]
  • x = [+$solution+] (sometimes solutions may be close approximations of the actual solutions)
  • Expression factored: [+ "$a"."x\2\" . sign( $signed_b ) . "$b"."x" . sign( $signed_c ) . "$c = " +] [+ $factored +]

  • See [+ lesson_link( "quadform" ) +]

Solution Explained

Equation: [+ plot_formula( "$a"."x^2" . sign( $signed_b ) . "$b"."x". sign( $signed_c ) . "$c = 0" ) +]

a = [+$a+]
b = [+$signed_b+]
c = [+$signed_c+]

Discriminant: b2-4ac = [+ $b +]2[+ sign( $ac4 ) . "4*" . term( $a ) . "*" . term( $signed_c ) . " = $discr"+]

[$ if $a != 0 $] [$ if $discr > 0 $] Discriminant ([+$discr+]) is greater than zero. The equation has two solutions.


[+ plot_formula( "x = (-b +- sqrt( b^2-4ac ) )/2a" ) +]

or

[+ plot_formula( "x = (-" . term($signed_b) . "+- sqrt( $b^2 " . sign( $ac4 ) . "4*" . term( $a ) . "*" . term( $signed_c ) . " ))/(2*" .term ($a) . ")" ) +]

[$ if( sqrt($discr) == int(sqrt($discr)) ) $]

or

x1,2 = ([+-$signed_b+] ± [+sqrt( $discr )+]) / [+2*$a+]
or

x1 = [+-$signed_b + sqrt( $discr )+] / [+2*$a+] = [+ $x1 = reduce_fraction( -$signed_b + sqrt( $discr ), 2*$a ) +]
x2 = [+-$signed_b - sqrt( $discr )+] / [+2*$a+] = [+ $x2 = reduce_fraction( -$signed_b - sqrt( $discr ), 2*$a ) +]

or

x1,2 = [+$solution+]

Equation factored: [+ $factored +] [$ else $] or [+ plot_formula( "x = (-" . term($signed_b) . "+- sqrt( $discr ) )/(2*" .term ($a) . ")" ) +]

[$ if( int($signed_b/2/$a) == $signed_b/2/$a || int( $discr/4/$a/$a ) == $discr/4/$a/$a ) $] Reducing it further, we have [+ plot_formula( term( reduce_fraction( -$signed_b, 2*$a ) ) . "+- sqrt( " . reduce_fraction( $discr, 4*$a*$a ) . ")" ) +] [$ endif $]

Since [+ plot_formula( "sqrt( $discr )" ) +] is not an integer number (it is a so called irrational number, not reducible to fractions like m/n), further reduction of this expression will not give you an integer result. [$ endif $] [$ elsif $discr == 0 $] Discriminant ([+$discr+]) is zero. There is only one solution.
x = -b/2a

or

x = [+-$signed_b+]/(2*[+$a+]) = [+-$signed_b+]/([+2*$a+]) = [+-$signed_b/(2*$a)+]
[$ else $] Discriminant ([+$discr+]) is less than zero. No solutions are defined.

Note: for those of you who study complex numbers, there is a complex solution. If you do not know what complex numbers are, do not worry about a complex solution and just accept the fact that there are no solutions to your problem. You will study complex numbers later in your school program (if ever). [$ endif $] [$ else $] [+ $solution +] [$ endif $] [NEW!]Check out Word Problems involving Quadratics!

Word Problem Example:

The length of a hypotenuse of a right triangle is 2 feet more than the longer leg. The length of the longer leg is 7 feet more than the lenth of the shorter leg. Find the number of feet in length of each side of the right triangle.

Solve This Problem Interactively / Customize This Problem


Back