The absolute value obviously came up with a variable, but the problem is the matrix and not the variable.
If I enter |3| instead of 3, the answer is also marked incorrect. In that case the error message is:
Matrix row entries must be numbers: [3]
The absolute value obviously came up with a variable, but the problem is the matrix and not the variable.
If I enter |3| instead of 3, the answer is also marked incorrect. In that case the error message is:
Matrix row entries must be numbers: [3]
Sorry for not looking into this earlier. I no longer get notifications of new message, and never saw it.
It turns out that this is due to the fact that absolute values are treated internally by the MathObject parser as a special kind of list (lists have opening and closing delimiters, like absolute values). But some of the code that builds matrices from their entries turn lists into sub-matrices, and that was being done to the absolute values, so the matrix was ending up looking like it was $$ \begin{bmatrix} 1 & [h+2] \\ 2 & 3 \end{bmatrix} $$ instead. That lead to the error about row entries must be numbers, since one of the entries was a (1 x 1) matrix.
The fix is the following:
diff --git a/lib/Parser/List/AbsoluteValue.pm b/lib/Parser/List/AbsoluteValue.pm index 6e2d552b..ab922627 100644 --- a/lib/Parser/List/AbsoluteValue.pm +++ b/lib/Parser/List/AbsoluteValue.pm @@ -23,6 +23,8 @@ sub _check { sub class {'AbsoluteValue'}; # don't report List +sub makeMatrix {} # override Parser::List method + # # Compute using abs() # diff --git a/lib/Parser/List/Matrix.pm b/lib/Parser/List/Matrix.pm index c14f6fa9..6374458d 100644 --- a/lib/Parser/List/Matrix.pm +++ b/lib/Parser/List/Matrix.pm @@ -15,7 +15,7 @@ sub _check { my $self = shift; my $matrix = $self->{equation}{context}{lists}{Matrix}; $self->{open} = $matrix->{open}; $self->{close} = $matrix->{close}; - if ($self->{entryType}{name} ne 'Matrix') { + if ($self->entryType->{name} ne 'Matrix') { foreach my $x (@{$self->{coords}}) {$x->makeMatrix($self->{type}{name},$self->{open},$self->{close})} }
Thank you. For now I converted the problem into asking for the matrix entries one-by-one as scalars, but I will definitely try these changes at some point.