WeBWorK Problems

Solve LR

Solve LR

by Olivia Henders -
Number of replies: 4

We are trying to use Solve LR to find the solution to this question (see image)

?ui=2&ik=ba77cfad9a&view=fimg&th=15dcd2543ad75aeb&attid=0.1&disp=emb&attbid=ANGjdJ8RQuDyFeFo71sXXRKHqGTJs80bwzU0WaSfwQr8_w0n-nj99zarim1Fw_YPhVY4pytdbu-wdu6LL8TqIpYecpQGIfpx5KAyBi3rYQ7ao_2OvWVvvo-wiVg3Wdk&sz=w1668-h558&ats=1502385364568&rm=15dcd2543ad75aeb&zw&atsh=1

However, instead of getting the expected answer (the matrix [[3],[-1]]) we’re getting a 2x2 zero matrix.

Applicable lines of code are listed below.

What are we doing incorrectly?

$v2D = ColumnVector(4,1);
$D = Matrix([[3,5],[1,2]]);
# Must be called by a Matrix MathObject.
$answerBi = $D->solve_LR(Matrix($v2D)->transpose);
BEGIN_PGML
bi. Solve LR
What is the solution to the system [`Dx = \vec{v}`]? [@ ans_box(4,30) @]* [@ AnswerFormatHelp("matrix") @]* 
 *Correct Answer(s):* [$answerBi]
 
 *Displayed Answer (after the due date):* [`[$answerBi]`]
END_PGML
ANS($answerBi->cmp()) 
In reply to Olivia Henders

Re: Solve LR

by Olivia Henders -
Sorry, the image failed to render for some reason. Please see http://imgur.com/tuVBLBt for the referenced image.
In reply to Olivia Henders

Re: Solve LR

by Davide Cervone -
The problem is that solve_LR doesn't return what you think it does. The method uses the corresponding one from the MatrixReal package, and that returns three things: the dimension, the resultant vector, and the base matrix. These are explained in the linked page (search for solve_LR). So you could do either
($d,$answerBi,$X) = $D->solve_LR(Matrix($v2D)->transpose);
or
$answerBi = ($D->solve_LR(Matrix($v2D)->transpose))[0];
to get the result that you are looking for. It turns out that if you assign the array of three to the scalar $answerBi, it gets assigned to the last element in the array (the base matrix), which is the 2x2 zero matrix you are seeing.
In reply to Davide Cervone

Re: Solve LR

by Olivia Henders -
Ahhh, that makes sense! We were trying to reference the result as an array, but using the wrong syntax for it. Thank you!
In reply to Olivia Henders

Re: Solve LR

by Davide Cervone -
It's an actual array, not an array reference, so that might have been the issue. Glad you have it worked out now.