IMathAS icon indicating copy to clipboard operation
IMathAS copied to clipboard

create parseStuansAsMatrix()

Open rpruim opened this issue 2 years ago • 3 comments

As per the discussion in this forum, I've created a function that takes a student-supplied calculated matrix and returns it as a matrix rather than as an array.

I have not updated the documentation. Is that done by manually updating the HTML? If so, we could put something like this in there:

<h3><a name="parseStuansAsMatrix">parseStuansAsMatrix</a></h3>
<p>parseStuansAsMatrix(student answer, eval)</p>
<p>Converts a students matrix answer into a matrix</p>
<p>student answer can come from <code>$stuanswers[$thisq]</code> for single-part
questions, or <code>getstuans($stuanswers, $thisq, (part index))</code> for
multi-part.  If <code>eval</code> is true (the default), expressions in a calculated matrix are evaluated before creating the matrix.</p>

rpruim avatar Jul 14 '23 16:07 rpruim

I've added an additional argument to control whether symbolic expressions are evaluated.

rpruim avatar Jul 14 '23 17:07 rpruim

Thanks for this. However since the evaluated values for the matrix are already present in $stuanswersval, I'm hesitant to have this function do the work of evaluating the expressions a second time, as that's pretty inefficient.

I'm thinking a more efficient pattern would be to have the optional second argument be the $stuanswersval entry. If provided, the function could still use $stuanswers from the first argument to determine the dimension, then use the second entry for the values.

It probably should also be noted that the function only works for matrix questions without $answersize set. That definitely has the potential to be confusing. Perhaps it would be better to have the function inputs be parseStuansAsMatrix(student answer, [answersize, student answer val]), where answersize would be null if answersize wasn't set on the question.

drlippman avatar Jul 27 '23 16:07 drlippman

This snuck past me in July. Sorry for that.

I'm basically in support of some good way to get a matrix and know it's shape without the question writer needing to do hacky things each time this happens. It is a bit confusing that parseStuAnsAsMatrix() doesn't parse as a matrix but only provides an array.

rpruim avatar Sep 08 '23 16:09 rpruim