-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from ChristopherChudzicki/matrix-docs
Version 1.2 documentation
- Loading branch information
Showing
36 changed files
with
1,731 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html display_name="MatrixGrader"> | ||
|
||
<p> | ||
<code>MatrixGrader</code> is an extended version of FormulaGrader used to grade mathematical expressions containing scalars, vectors, and matrices. Authors and students may enter matrix (or vector) expressions by using variables sampled from matrices, or by entering a matrix entry-by-entry. | ||
</p> | ||
|
||
<p>Examples below. See also the <a href="https://mitodl.github.io/mitx-grading-library/matrix_grader">full documetnation</a>.</p> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<problem display_name="Sibling Variables" showanswer="always" weight="10" attempts=""> | ||
|
||
<script type="loncapa/python"> | ||
from mitxgraders import ListGrader, NumericalGrader | ||
|
||
initial_subgrader = NumericalGrader(tolerance=2) | ||
iteration_subgrader = NumericalGrader( | ||
tolerance=1e-6, | ||
user_functions={ | ||
# these are just for convenience when specifying answer above. | ||
# Students could use them, but we will not announce their existence | ||
'f' : lambda x: x**2 - 9, # root is x = sqrt(9) | ||
'df': lambda x: 2*x # derivative of f | ||
} | ||
) | ||
|
||
grader = ListGrader( | ||
ordered=True, | ||
answers=[ | ||
'5', # anything between 4 and 6 accepted | ||
'sibling_1 - f(sibling_1)/df(sibling_1)', | ||
'sibling_2 - f(sibling_2)/df(sibling_2)', | ||
], | ||
subgraders=[ | ||
initial_subgrader, | ||
iteration_subgrader, | ||
iteration_subgrader | ||
] | ||
) | ||
</script> | ||
|
||
<p> | ||
When a student submits several mathematical inputs as part of one problem, it is sometimes useful to grade these inputs in comparison to each other. This problem uses sibling variables to score subsequent answers based off of the previous one. Sibling variables are available to <code>FormulaGrader</code>s, <code>NumericalGrader</code>s, and <code>MatrixGrader</code>s when used inside an <strong>ordered</strong> <code>ListGrader</code>. | ||
</p> | ||
|
||
<p> | ||
Use Newton's Method on \(f(x)=x^2 - 9\) to calculate the square root of 9. Use anything in the interval \( (4, 6) \) as your starting value. Round answers to no fewer than 6 decimal places. | ||
</p> | ||
|
||
<p>Suggested inputs:</p> | ||
<ul> | ||
<li><code>[5, 3.4, 3.0235294]</code> is a correct input</li> | ||
<li><code>[4.5, 3.25, 3.0096154]</code> is a correct input</li> | ||
<li>Try changing one or two values in the lists above.</li> | ||
</ul> | ||
|
||
<customresponse cfn="grader"> | ||
<table> | ||
<tr> | ||
<th></th> | ||
<th>value</th> | ||
</tr> | ||
<tr> | ||
<td>\(x_0\)</td> | ||
<td><textline /></td> | ||
</tr> | ||
<tr> | ||
<td>\(x_1\)</td> | ||
<td><textline /></td> | ||
</tr> | ||
<tr> | ||
<td>\(x_2\)</td> | ||
<td><textline /></td> | ||
</tr> | ||
</table> | ||
</customresponse> | ||
|
||
<h3>Resources</h3> | ||
<ul> | ||
<li> | ||
<a href="https://github.com/mitodl/mitx-grading-library/tree/master/course/problem/list6.xml" target="_blank">View source</a> | ||
</li> | ||
<li> | ||
<a href="https://mitodl.github.io/mitx-grading-library/grading_math/formula_grader/#sibling-variables" target="_blank">Documentation for sibling variables</a> | ||
</li> | ||
</ul> | ||
|
||
</problem> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<problem display_name="MatrixGrader: First Example" showanswer="always" weight="10" attempts=""> | ||
|
||
<script type="text/python" system_path="python_lib"> | ||
from mitxgraders import MatrixGrader, RealMatrices, RealVectors | ||
|
||
grader = MatrixGrader( | ||
answers='4*A*B^2*v', | ||
variables=['A', 'B', 'v'], | ||
sample_from={ | ||
'A': RealMatrices(), # samples from 2 by 2 matrices by default | ||
'B': RealMatrices(), | ||
'v': RealVectors(shape=2) | ||
}, | ||
identity_dim=2 | ||
) | ||
</script> | ||
|
||
<p>This is a demo problem with 3 variables: <code>A</code> and <code>B</code> are 2 by 2 matrices, while <code>v</code> is a vector of length 2.</p> | ||
|
||
<p>Try inputting different forms of the correct answer, as well as different incorrect answers:</p> | ||
<ul> | ||
<li><code>4*A*B^2*v</code> is correct</li> | ||
<li><code>A*(2*B^2 + 2*B*I*B)*v</code> is also correct; here <code>I</code> is the 2 by 2 identity matrix.</li> | ||
<li><code>4*B*A*B*v</code> is incorrect (non-commutative)</li> | ||
<li>The following answers will raise interesting errors: | ||
<ul> | ||
<li><code>A + v</code></li> | ||
<li><code>v^2</code></li> | ||
<li><code>A^2.5</code></li> | ||
<li><code>4*A*B^2</code></li> | ||
</ul> | ||
</li> | ||
</ul> | ||
|
||
<customresponse cfn="grader" expect="4*A*B^2*v"> | ||
<textline math="true" preprocessorClassName="MJxPrep" preprocessorSrc="/static/MJxPrep.js" /> | ||
</customresponse> | ||
|
||
<a href="https://github.com/mitodl/mitx-grading-library/tree/master/course/problem/matrix1.xml" target="_blank">View source</a> | ||
|
||
|
||
</problem> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<problem display_name="MatrixGrader: Entry-by-entry input" showanswer="always" weight="10" attempts=""> | ||
|
||
<script type="text/python" system_path="python_lib"> | ||
from mitxgraders import MatrixGrader, RealMatrices, RealVectors | ||
|
||
grader = MatrixGrader( | ||
answers='[[-cos(theta), -sin(theta)], [-sin(theta), cos(theta)]]', | ||
variables=['theta'], | ||
max_array_dim=2 | ||
) | ||
</script> | ||
|
||
<p>A linear transformation \(\mathcal{T}: \mathbb{R}^2 \rightarrow \mathbb{R}^2\) rotates vectors counter-clockwise by angle \(\theta\) then reflects them over the \(y\)-axis. Enter the matrix representation of \(\mathcal{T}\).</p> | ||
|
||
<p>This problem requires entry-by-entry input of a matrix. Suggested inputs:</p> | ||
|
||
<ul> | ||
<li><code>[[-cos(theta), -sin(theta)], [-sin(theta), cos(theta)]]</code>, correct answers</li> | ||
<li><code>-[[cos(theta), sin(theta)], [sin(theta), -cos(theta)]]</code>, also correct</li> | ||
<li>Try inputting ill-formed matrices such as <code>[[1, 2], [3]]</code></li> | ||
</ul> | ||
|
||
<customresponse cfn="grader" expect="[[-cos(theta), -sin(theta)], [-sin(theta), cos(theta)]]"> | ||
<textline math="true" preprocessorClassName="MJxPrep" preprocessorSrc="/static/MJxPrep.js" size="100" /> | ||
</customresponse> | ||
|
||
<a href="https://github.com/mitodl/mitx-grading-library/tree/master/course/problem/matrix2.xml" target="_blank">View source</a> | ||
|
||
|
||
</problem> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<problem display_name="MatrixGrader: Cross Product Demo" showanswer="always" weight="10" attempts=""> | ||
|
||
<script type="text/python" system_path="python_lib"> | ||
from mitxgraders import MatrixGrader, RealMatrices, RealVectors | ||
|
||
grader = MatrixGrader( | ||
answers='abs(cross(vecb-veca, vecc-veca))/abs(vecb-veca)', | ||
variables=['veca', 'vecb', 'vecc'], | ||
sample_from={ | ||
'veca': RealVectors(shape=3), | ||
'vecb': RealVectors(shape=3), | ||
'vecc': RealVectors(shape=3) | ||
} | ||
) | ||
</script> | ||
|
||
<p>A line goes through points \( \vec{a}, \vec{b} \in \mathbb{R}^3 \). Give an expression for the minimum distance from this line to a third point \( \vec{c} \).</p> | ||
|
||
<ul> | ||
<li>You may enter \(\vec{a}\), \(\vec{b}\), and \(\vec{c}\) as <code>veca</code>, <code>vecb</code>, and <code>vecc</code>.</li> | ||
<li>Use <code>cross(a, b)</code> for \( \vec{a} \times \vec{b}\)</li> | ||
</ul> | ||
|
||
<p>This demo problem is primarily intended to show off the cross product. Some suggested inputs:</p> | ||
|
||
<ul> | ||
<li> | ||
<code>abs(cross(vecb-veca, vecc-veca))/abs(vecb-veca)</code> is correct, | ||
</li> | ||
<li> | ||
<code>abs(cross(vecb-veca, vecc-vecb))/abs(vecb-veca)</code> is also correct | ||
</li> | ||
<li> | ||
<code>cross(1, [1, 2, 3])</code> to see hepful error messages. All standard functions (<code>norm</code>, <code>trans</code>, <code>det</code>, ...) provided by the MatrixGrader class give similar error messages when something goes wrong. | ||
</li> | ||
</ul> | ||
|
||
<customresponse cfn="grader" expect="abs(cross(vecb - veca, vecc - veca))/abs(vecb - veca)"> | ||
<textline math="true" preprocessorClassName="MJxPrep" preprocessorSrc="/static/MJxPrep.js" size="100" /> | ||
</customresponse> | ||
|
||
<a href="https://github.com/mitodl/mitx-grading-library/tree/master/course/problem/matrix3.xml" target="_blank">View source</a> | ||
|
||
|
||
</problem> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<problem display_name="MatrixGrader: Vectors vs single-row/column matrix" showanswer="always" weight="10" attempts=""> | ||
|
||
<script type="text/python" system_path="python_lib"> | ||
from mitxgraders import MatrixGrader | ||
|
||
grader_1 = MatrixGrader( | ||
answers='[1, 2]', | ||
max_array_dim=1 # this is the default, so we did not really need to set it | ||
) | ||
|
||
grader_2 = MatrixGrader( | ||
answers='[1, 2]', | ||
max_array_dim=2 # students may enter vectors or matrices | ||
) | ||
</script> | ||
|
||
<p>This pair of graders is intended to display how MatrixGrader treats vectors, single-row matriecs, and single-column matrices as different objects. The problems are identical, except that the second problem allows entry-by-entry matrix input.</p> | ||
|
||
<p>Suggested inputs:</p> | ||
|
||
<ul> | ||
<li> | ||
Correct answers: | ||
<ul> | ||
<li><code>[1, 2]</code></li> | ||
<li><code>trans([1, 2])</code>, transpose does nothing to vectors</li> | ||
<li><code>[[1, 0], [0, 1]] * [1, 2]</code></li> | ||
<li><code>[1,2] * [[1, 0], [0, 1]]</code></li> | ||
</ul> | ||
</li> | ||
<li><code>[[1, 2]]</code>, single-row matrix, incorrect</li> | ||
<li><code>[[1], [2]]</code>, single-column matrix, incorrect</li> | ||
</ul> | ||
|
||
<table> | ||
<tr> | ||
<th style="width:40%">Only vector input is allowed</th> | ||
<th style="width:40%">Vector and matrix input allowed</th> | ||
</tr> | ||
<tr> | ||
<td> | ||
<customresponse cfn="grader_1" expect="[1, 2]"> | ||
<textline math="true" preprocessorClassName="MJxPrep" preprocessorSrc="/static/MJxPrep.js" size="40" /> | ||
</customresponse> | ||
</td> | ||
<td> | ||
<customresponse cfn="grader_2" expect="[1, 2]"> | ||
<textline math="true" preprocessorClassName="MJxPrep" preprocessorSrc="/static/MJxPrep.js" size="40" /> | ||
</customresponse> | ||
</td> | ||
</tr> | ||
</table> | ||
|
||
<h3>Avoiding Confusion</h3> | ||
<p>In "real" problems, we strongly recommend disallowing entry-by-entry matrix input (which is the default) unless it is needed, to avoid potential confusion between <code>[1, 2]</code> and <code>[[1, 2]]</code></p> | ||
|
||
<a href="https://github.com/mitodl/mitx-grading-library/tree/master/course/problem/matrix4.xml" target="_blank">View source</a> | ||
|
||
</problem> |
Oops, something went wrong.