Solver SOLVE linear system by SUBSTITUTION
Algebra
->
Equations
-> Solver SOLVE linear system by SUBSTITUTION
Log On
Algebra: Equations
Section
Solvers
Solvers
Lessons
Lessons
Answers archive
Answers
Source code of 'SOLVE linear system by SUBSTITUTION'
This Solver (SOLVE linear system by SUBSTITUTION)
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 Variable names: *[input X=x] *[input Y=y] *[input a11=1]X + *[input a12=-1]Y = *[input b1=0] *[input a21=1]X + *[input a22=1]Y = *[input b2=2] ==section solution perl print "Solve: {{{ system( $a11\\$X + $a12\\$Y = $b1, $a21\\$X + $a22\\$Y = $b2 ) }}}"; if( $a11 != 0 ) { print "We'll use substitution. After moving $a12*$Y to the right, we get: {{{$a11*$X = $b1 - $a12*$Y}}}, or {{{$X = $b1/$a11 - $a12*$Y/$a11}}}. Substitute that into another equation: {{{$a21*($b1/$a11 - $a12*$Y/$a11) + $a22\\$Y = $b2}}} and simplify: "; my $simplified = solve( "explain_simplification", "$a21*($b1/$a11 - $a12*$Y/$a11) + $a22\\$Y = $b2" ); $y = $simplified; $y =~ s/^.*?\;\w+=//; $x = $b1/$a11 - $a12*$y/$a11; print "So, we know that $Y=$y. Since {{{$X = $b1/$a11 - $a12*$Y/$a11}}}, $X=$x. Answer: {{{system( $X=$x, $Y=$y )}}}. "; } else { if( $a12 == 0 ) { print "You have a bad equation system, in the first equation, both coefficients are 0."; return 0; } print "The first equation is an easy equation for $Y: {{{$Y = $b1/$a12}}}.\n\n"; $y = $b1/$a12; print "Knowing $Y, we can substitute it into the second equation: {{{$a21*$X+$a22*$b1/$a12 = $b2}}}. From here, {{{$X=($b2-$a22*$b1/$a12)/$a21}}}"; $x = solve( "explain_simplification", "($b2-$a22*$b1/$a12)/$a21" ); $x =~ s/;//; print "Your answer: {{{system( $X=$x, $Y=$y ) }}}.\n"; } ==section output x y ==section check X=x Y=y a11=0 a12=-1 b1=0 a21=1 a22=1 b2=2 x=2 y=-0 X=x Y=y a11=1 a12=-1 b1=0 a21=1 a22=1 b2=2 x=1 y=1 ==section practice perl $a11 = randint( 1, 3 ); $a12 = randint( 1, 3 ); $a21 = randint( 1, 3 ); $a22 = randint( 1, 3 ); my $x1 = randint( -1, 4 ); my $x2 = randint( -1, 4 ); $b1 = $a11*$x1 + $a12*$x2; $b2 = $a21*$x1 + $a22*$x2;