Solver SOLVE quadratic equation with variable
Algebra
->
Customizable Word Problem Solvers
->
Travel
-> Solver SOLVE quadratic equation with variable
Log On
Ad:
Over 600 Algebra Word Problems at edhelper.com
Word Problems: Travel and Distance
Word
Solvers
Solvers
Lessons
Lessons
Answers archive
Answers
Source code of 'SOLVE quadratic equation with variable'
This Solver (SOLVE quadratic equation with variable)
was created by by
ichudov(507)
:
View Source
,
Show
,
Put on YOUR site
About ichudov
:
I am not a paid tutor, I am the owner of this web site!
==section input Solve for variable *[input v=x] this equation: *[input a=1]x<SUP>2</SUP>+*[input b=-1]x+*[input c=-2] = 0. You can put negative numbers if you need to use a negative coefficient. The variable that you specify will be used instead of x. ==section solution perl my $d = $b*$b-4*$a*$c; if( $a == 0 ) { print "Come on, this is not a quadratic equation!\n"; return; } print "Quadratic equation {{{a$v^2+b$v+c=0}}} (in our case {{{$a$v^2+$b"."$v+$c = 0}}}) has the following solutons: {{{$v"."[12] = (b+-sqrt( b^2-4ac ))/2\\a}}} For these solutions to exist, the <U>discriminant</U> {{{b^2-4ac}}} should not be a negative number. First, we need to compute the discriminant {{{b^2-4ac}}}: {{{b^2-4ac=($b)^2-4*$a*$c=$d}}}. "; my ($x1, $x2); my $middle = -$b/2/$a; if( $d > 0 ) { $x = $x1 = (- $b+sqrt( $d ))/2/$a; $x2 = (- $b-sqrt( $d ))/2/$a; print "Discriminant d=$d is greater than zero. That means that there are two solutions: {{{ x[12] = (-$b+-sqrt( $d ))/2\\a}}}. {{{$v\[1] = (-($b)+sqrt( $d ))/2\\$a = $x1}}} {{{$v\[2] = (-($b)-sqrt( $d ))/2\\$a = $x2}}} Quadratic expression {{{$a$v^2+$b$v+$c}}} can be factored: {{{$a$v^2+$b$v+$c = $a($v-$x1)*($v-$x2)}}} "; } elsif( $d == 0 ) { $x = $x1 = $x2 = -$b/2/$a; print "Discriminant d=$d is zero! That means that there is only one solution: {{{$v = (-($b))/2\\$a}}}. Expression can be factored: {{{$a$v^2+$b$v+$c = $a($v-$x1)*($v-$x2)}}} "; } else { # d < 0 my $sd = sqrt( -$d ); print "The discriminant $d is less than zero. That means that there are no solutions among real numbers.<BR> If you are a student of advanced school algebra and are aware about <u>imaginary numbers<u>, read on.<BR> In the field of imaginary numbers, the square root of $d is + or - {{{sqrt( " . (-$d) . ") = $sd}}}. The solution is {{{$v\[12] = (-$b+- i*sqrt( $d ))/2\\$a = (-$b+- i*$sd)/2\\$a }}} "; } if( defined $x1 && defined $x2 ) { print "Again, the answer is: $x1, $x2.\n"; } print "Here's your graph:\n\n{{{graph( 500, 500, -10, 10, -20, 20, $a*x^2+$b*x+$c )}}}"; ==section output x ==section check a=1 b=0 c=0 x1=1