Solver Linear Systems by Addition
Algebra
->
Expressions-with-variables
-> Solver Linear Systems by Addition
Log On
Algebra: Expressions involving variables, substitution
Section
Solvers
Solvers
Lessons
Lessons
Answers archive
Answers
Source code of 'Linear Systems by Addition'
This Solver (Linear Systems by Addition)
was created by by
aaaaaaaa(138)
:
View Source
,
Show
,
Put on YOUR site
About aaaaaaaa
:
==section input Variable names: *[input X=x] *[input Y=y] *[input x1=1]X + *[input y1=-1]Y = *[input b1=0] *[input x2=1]X + *[input y2=1]Y = *[input b2=2] ==section solution perl print "We'll solve the system: {{{$x1*$X + $y1*$Y = $b1}}} {{{$x2*$X + $y2*$Y = $b2}}} by elimination by addition."; my $neg=-1*$x1; my $diff=$neg/$x2; print "To eliminate by addition, we need to set both coefficients of x to numbers with changed signs, i.e a and -a. Since in the second equation we have $x2 as our coefficient for x, to get $neg we have to multiply all terms of the second equation by {{{$neg/$x2}}} which is equal to $diff. Multiplying, we get on our second equation:"; my $x3=$x2*$diff; my $y3=$y2*$diff; my $b3=$b2*$diff; print "{{{($x2*$diff)$X + ($y2*$diff)$Y = $b2*$diff}}} {{{$x3*$X + $y3*$Y = $b3}}} Adding both equations we get: {{{($x1+$x3)$X + ($y1+$y3)$Y = ($b1+$b3)}}} Since $x1 and $x3 cancel out, we have a linear equation:"; my $y4=$y1+$y3; my $b4=$b1+$b3; my $y=$b4/$y4; my $y5=$y1*$y; my $x=($b1 - $y5)/$x1; my $temp=$b1 - $y5; my $y = solve( "linear_equation", $Y, $y4, 0, $b4); print "Therefore, we know that $Y = $y. Plugging that in into the first equation gives us: {{{$x1*$X + $y1*$Y = $b1}}} {{{$x1*$X + $y1*$y = $b1}}} {{{$x1*$X + $y5 = $b1}}} {{{$x1*$X = $b1 - $y5}}} {{{$X = ($b1 - $y5)/$x1}}} {{{$X = $temp/$x1}}} {{{$X = $x}}} Therefore, our answer is: {{{system( $X=$x, $Y=$y )}}}"; ==section output x y ==section check X=x Y=y x1=1 y1=-1 b1=0 x2=1 y2=1 b2=2 x= y=