|
12 | 12 | ## Level(2) |
13 | 13 | ## Tagged by cmd6a 5/3/06 |
14 | 14 |
|
15 | | - |
16 | 15 | ########################################################################### |
17 | 16 | # initialization |
18 | 17 | ########################################################################### |
19 | 18 | DOCUMENT(); |
20 | 19 | loadMacros( |
21 | 20 | "PGstandard.pl", |
22 | 21 | "MathObjects.pl", |
| 22 | + "PGML.pl", |
23 | 23 | "parserMultiAnswer.pl", |
24 | 24 | "PGcourse.pl" |
25 | 25 | ); |
26 | 26 |
|
27 | | -TEXT(beginproblem()); |
28 | | -$showPartialCorrectAnswers = 1; |
29 | | - |
30 | | - |
31 | 27 | ########################################################################### |
32 | 28 | # setup contexts and variables |
33 | 29 | ########################################################################### |
34 | | -Context("Matrix"); |
35 | 30 |
|
36 | | -$sign1 = random(-1,1,2); |
37 | | -$a = random(2,5,1) * $sign1; |
38 | | -$b = random(3,9,1) * $sign1; |
| 31 | +Context("Vector"); |
39 | 32 |
|
| 33 | +$sign1 = random(-1,1,2); |
40 | 34 | $sign2 = random(-1,1,2); |
41 | | -$c = random(1,6,1) * $sign2; |
| 35 | +$sign3 = random(-1,1,2); |
| 36 | +$sign4 = random(-1,1,2); |
42 | 37 | $d = random(3,6,1); |
43 | | -$epd = random(-1,1,2); |
44 | | -$e = $epd - $d; |
45 | | -$f = random(3,9,1) * $sign2; |
46 | | -$m = random(2,3,1) * random(-1,1,2); |
47 | | -$g = $m * ($e + $d); |
48 | | -$h = $m * ($e * $a + $b); |
49 | | -$i = $m * ($e * $c + $f); |
| 38 | +$m = random(2,3,1)*$sign4; |
| 39 | + |
| 40 | +# R1,R2,R3 are the rows of a 3x4 matrix with rank 2 |
| 41 | + |
| 42 | +$R1 = Vector(1,-1,random(2,5,1)*$sign1, random(1,6,1)*$sign2); |
| 43 | +$R2 = Vector($d, $sign3 - $d, random(3,9,1)*$sign1, random(3,9,1)*$sign2); |
| 44 | +$R3 = $m*($sign3-$d)*$R1 + $m*$R2; |
| 45 | + |
| 46 | +# the 3x4 matrix |
| 47 | + |
| 48 | +$M = Matrix([[$R1->value],[$R2->value],[$R3->value]]); |
50 | 49 |
|
51 | | -# matrix representing left hand side of equation |
| 50 | +# for latex display |
52 | 51 |
|
53 | | -$A = Matrix([ |
54 | | - [1 ,-1,$a], |
55 | | - [$d,$e,$b], |
56 | | - [$g, 0,$h] |
57 | | -]); |
| 52 | +($a11,$a12,$a13,$a14) = ($R1->value); |
| 53 | +($a21,$a22,$a23,$a24) = ($R2->value); |
| 54 | +($a31,$a32,$a33,$a34) = ($R3->value); |
58 | 55 |
|
59 | | -# for answer |
| 56 | +$pm13 = ($a13 < 0) ? "-" : "+"; |
| 57 | +$pm22 = ($a22 < 0) ? "-" : "+"; |
| 58 | +$pm23 = ($a23 < 0) ? "-" : "+"; |
| 59 | +$pm33 = ($a33 < 0) ? "-" : "+"; |
60 | 60 |
|
61 | | -$k = $a + $epd * ($b - $a*$d); |
62 | | -$l = $epd * ($b - $a*$d); |
63 | | -$mm = $c + $epd * ($f - $c*$d); |
64 | | -$n = $epd * ($f - $c*$d); |
| 61 | +# particular solution xp with xp3=0 |
65 | 62 |
|
66 | | -#expected answers |
67 | | -$V1=ColumnVector($mm,$n,0); |
68 | | -$V2=ColumnVector(-$k,-$l,1); |
| 63 | +$xp2 = $sign3*($a24-$d*$a14); |
| 64 | +$xp1 = $xp2 + $a14; |
69 | 65 |
|
70 | | -#for tex display |
| 66 | +$xp = ColumnVector($xp1,$xp2,0); |
71 | 67 |
|
72 | | -$pm1 = ($a < 0) ? "-" : "+"; |
73 | | -$pm2 = ($e < 0) ? "-" : "+"; |
74 | | -$pm3 = ($b < 0) ? "-" : "+"; |
75 | | -$pm4 = ($h < 0) ? "-" : "+"; |
| 68 | +# homogeneous solution xh with xh3 = 1 |
76 | 69 |
|
77 | | -$c1 = abs($a); |
78 | | -$c2 = abs($e); |
79 | | -$c3 = abs($b); |
80 | | -$c4 = abs($h); |
| 70 | +$xh2 = -$sign3*($a23-$d*$a13); |
| 71 | +$xh1 = $xh2 - $a13; |
81 | 72 |
|
| 73 | +$xh = ColumnVector($xh1, $xh2, 1); |
82 | 74 |
|
83 | | -$multians = MultiAnswer($V1,$V2)->with( |
| 75 | +$ans = MultiAnswer($xp, $xh)->with( |
84 | 76 | singleResult => 0, |
85 | 77 | checker => sub { |
86 | 78 | my ($correct, $student, $self)=@_; |
87 | | - my ($stu1,$stu2)= @{$student}; |
88 | | - $check1 = ( $A*$stu1 == Matrix([[$c],[$f],[$i]]) ); |
89 | | - $check2a = ( $A*$stu2 == Matrix([[ 0],[ 0],[ 0]]) ); |
90 | | - $check2b = ($stu2->isZero); |
91 | | - if ( ! $check1 ){ |
92 | | - $self->setMessage(1,"Doesn't satisfy the given equation."); |
93 | | - } |
94 | | - if ( ! $check2a){ |
95 | | - $self->setMessage(2,"This vector points in the wrong direction."); |
96 | | - } |
97 | | - elsif ( $check2b ){ |
98 | | - $self->setMessage(2,"Can't be zero; equation has infinitely many solutions."); |
99 | | - } |
100 | | - return [ $check1, $check2a && ! $check2b ]; |
101 | | - } |
102 | | -); |
| 79 | + my ($stu_p,$stu_h)= @{$student}; |
| 80 | + if ($stu_h->isZero){ $self->setMessage(2,"Can't be zero; equation has infinitely many solutions.");} |
| 81 | + # augment student vectors with a fourth component |
| 82 | + my @stu_p = ($stu_p->extract(1),$stu_p->extract(2),$stu_p->extract(3)); |
| 83 | + my @stu_h = ($stu_h->extract(1),$stu_h->extract(2),$stu_h->extract(3)); |
| 84 | + push @stu_p, -1; |
| 85 | + push @stu_h, 0; |
| 86 | + $stu_p = Vector(@stu_p); |
| 87 | + $stu_h = Vector(@stu_h); |
| 88 | + my @check = (0,0); |
| 89 | + if ( ($M*$stu_p)->isZero ){$check[0]=1;} |
| 90 | + else {$self->setMessage(1,"Doesn't satisfy the given equation.");} |
| 91 | + if ( ($M*$stu_h)->isZero ){$check[1]=1;} |
| 92 | + else {$self->setMessage(2,"Must satisfy the corresponding homogeneous equation.");} |
| 93 | + return @check; |
| 94 | + }); |
103 | 95 |
|
| 96 | +BEGIN_PGML |
| 97 | +Use Gauss-Jordan reduction to solve the following linear system: |
104 | 98 |
|
105 | | -########################################################################### |
106 | | -# state the problem |
107 | | -########################################################################### |
108 | | -Context()->texStrings; |
109 | | -BEGIN_TEXT |
110 | | -Use the Gauss-Jordan reduction to solve the following linear system: |
111 | | -$PAR |
112 | | -\[ \left\{'\{'\} \begin{array}{rcrcrcr} |
113 | | - x_1 & - & x_2 & $pm1 & $c1 x_3 & = & $c \cr |
114 | | - $d x_1 & $pm2 & $c2 x_2 & $pm3 & $c3 x_3 & = & $f \cr |
115 | | - $g x_1 & & & $pm4 & $c4 x_3 & = & $i |
116 | | -\end{array} \right. \] |
117 | | -$PAR |
118 | | -$BCENTER |
119 | | -\(\left[\begin{array}{c} x_1 \\ x_2 \\ x_3 \end{array} \right]\) |
120 | | - \(=\) \{$multians->ans_array\} \(\ +\ s\ \)\{$multians->ans_array\} |
121 | | -$ECENTER |
122 | | -END_TEXT |
123 | | -Context()->normalStrings; |
124 | | - |
125 | | -#\{ mbox('\(\left[\begin{array}{c} x_1 \\ x_2 \\ x_3 \end{array} \right]\)', |
126 | | -#'\(\quad =\)', ans_array(3,1,5), '\(+\)', ans_array_extension(3,1,5), '\(s\).' ) \} |
| 99 | + [`` \left\{\ \ \begin{array}{rcrcrcr} x_1 & - & x_2 & [$pm13] & [@ abs($a13) @] x_3 & = & [$a14] \\ [$a21] x_1 & [$pm22] & [@ abs($a22) @] x_2 & [$pm23] & [@ abs($a23) @] x_3 &=& [$a24] \\ [$a31] x_1 & & & [$pm33] & [@ abs($a33) @] x_3 &=& [$a34] \end{array} \right.``] |
127 | 100 |
|
| 101 | + [`` \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} ``] = [_]*{$ans} + s [_]*{$ans} |
| 102 | +END_PGML |
128 | 103 |
|
129 | | -########################################################################### |
130 | | -# check the answer |
131 | | -########################################################################### |
132 | | -#ANS(vec_solution_cmp([[$m, $n, 0], [- $k , -$l, 1]])); |
| 104 | +# used in solution |
133 | 105 |
|
134 | | -ANS($multians->cmp()); |
| 106 | +$M1 = Matrix([[$R1->value],[($R2 - $d*$R1)->value], [($R3-$m*$sign3*$R1)->value]]); |
| 107 | + |
| 108 | +$M2 = Matrix([[$R1->value],[($R2 - $d*$R1)->value], [0,0,0,0] ]); |
| 109 | + |
| 110 | +BEGIN_PGML_SOLUTION |
| 111 | +The augmented matrix for this system is |
| 112 | + |
| 113 | + [`` [$M] ``]. |
| 114 | + |
| 115 | +Add [@ -$d @] times row 1 to row 2, and [@ -$m*$sign3 @] times row 1 to row 3, to obtain |
| 116 | + |
| 117 | + [`` [$M1] ``]. |
| 118 | + |
| 119 | +Add [@ -$m @] times row 2 to row 3 |
| 120 | + |
| 121 | + [`` [$M2] ``]. |
| 122 | + |
| 123 | +Thus the original system is equivalent to |
| 124 | + |
| 125 | + [`` \begin{gather} |
| 126 | +x_1-x_2+[$a13]x_3 = [$a14] \\ |
| 127 | +([$sign3])x_2 + ([@ $a23-$d*$a13 @])x_3= [@ $a24-$d*$a14 @] |
| 128 | +\end{gather} ``] |
| 129 | + |
| 130 | +or equivalently, solving for [`x_2`] first then [`x_1`], |
| 131 | + |
| 132 | + [`` \begin{align} |
| 133 | +x_2 &= [@ $sign3*($a24-$d*$a14) @] + ([@ ($a23-$d*$a13) @])x_3 \\ |
| 134 | +x_1 &= [$a14] +x_2 + ([@ -$a13 @])x_3 = [@ $a14 + $sign3*($a24-$d*$a14) @] + ([@ -$a13 + ($a23-$d*$a13) @])x_3 |
| 135 | +\end{align} ``] |
| 136 | + |
| 137 | +Therefore [`x_3`] is a free variable so there are infinitely many solutions. One may parametrize them with the parameter [`s`] that is given in the problem by setting [`x_3 = s`], so the parametrized solution becomes |
| 138 | + |
| 139 | + [``\begin{align} x_1 & = [@ $a14 + $sign3*($a24-$d*$a14) @] + ([@ -$a13 + ($a23-$d*$a13) @])s \\ |
| 140 | + x_2 &= [@ $sign3*($a24-$d*$a14) @] + ([@ ($a23-$d*$a13) @])s \\ |
| 141 | + x_3 &= s |
| 142 | +\end{align} ``], |
| 143 | + |
| 144 | +or, equivalently, |
| 145 | + |
| 146 | + [``\begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} |
| 147 | += [$xp] + s [$xh] . ``] |
| 148 | + |
| 149 | +In fact there are infinitely many different solutions. For given any two real numbers [`a`] and [`b`] with [`a\neq 0`] one could create another parameter [`t = as + b`] and parametrize the solutions by [`t`]: |
| 150 | + |
| 151 | + [``\begin{align} |
| 152 | +\begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} |
| 153 | +&= [$xp] + t [$xh] \\ |
| 154 | +&= [$xp] + (as + b) [$xh] \\ |
| 155 | +&= \left([$xp]+b[$xh]\right) + s \left(a[$xh]\right). \end{align} ``] |
| 156 | + |
| 157 | +This means that, in the "official" solution given above, one could replace [`[$xp]`] with [`\left([$xp]+b[$xh]\right)`] and replace [`[$xh]`] with [`\left(a[$xh]\right)`], and get another solution that would work equally well. (The condition [`a\neq 0`] ensures that as [`s`] ranges over all the real numbers [`t`] does also.) |
| 158 | + |
| 159 | +END_PGML_SOLUTION |
135 | 160 |
|
136 | | -########################################################################### |
137 | | -# solution |
138 | | -########################################################################### |
139 | | -$e1 = -$k; |
140 | | -$e2 = -$l; |
141 | | - |
142 | | -Context()->texStrings; |
143 | | -BEGIN_SOLUTION |
144 | | -$PAR $BBOLD SOLUTION: $EBOLD |
145 | | -By using the Gauss-Jordan reduction, we can find the reduced row echelon form of the augmented matrix of our system which turns out to be: |
146 | | -$PAR |
147 | | -\[ \left[ |
148 | | -\begin{array}{rrr|r} |
149 | | -1 & 0 & $k & $mm \cr |
150 | | -0 & 1 & $l & $n \cr |
151 | | -0 & 0 & 0 & 0 |
152 | | -\end{array} |
153 | | -\right] \] |
154 | | -$PAR |
155 | | -Hence, \(x_1,x_2\) are lead variables and \(x_3\) is the only free variable. By writing down the system corresponding to the RRE form, we get that |
156 | | -$PAR |
157 | | -\[ |
158 | | -x_1 = $mm + $e1 x_3 \qquad \mbox{and} \qquad x_2 = $n + $e2 x_3, |
159 | | -\] |
160 | | -$PAR |
161 | | -where \(x_3\) is free (can take any value). Therefore every vector of the form |
162 | | -$PAR |
163 | | -\[ |
164 | | -\left[ |
165 | | -\begin{array}{r} |
166 | | -x_1 \\ x_2 \\ x_3 |
167 | | -\end{array} |
168 | | -\right] |
169 | | - = |
170 | | -\left[ |
171 | | -\begin{array}{r} |
172 | | -$mm \\ $n \\ 0 |
173 | | -\end{array} |
174 | | -\right] |
175 | | -+ |
176 | | -\left[ |
177 | | -\begin{array}{r} |
178 | | -$e1 \\ $e2 \\ 1 |
179 | | -\end{array} |
180 | | -\right] s |
181 | | -\] |
182 | | -$PAR |
183 | | -is a solution, and every solution has that form for some value of \(s\). |
184 | | -END_SOLUTION |
185 | | -Context()->normalStrings; |
186 | 161 |
|
187 | 162 | COMMENT('Edited and updated in 2012/2013 by Rick Lynch @ Mizzou. Originally taken from NPL. |
188 | 163 | $BR |
|
0 commit comments