1
$\begingroup$

I solved a linear system which returned:

{{A[0, 0] -> 0, A[0, 1] -> 0, A[0, 2] -> 1, A[0, 3] -> 4, 
  A[0, 4] -> 5, A[0, 5] -> 2, A[0, 6] -> 0, A[1, 0] -> 0, 
  A[1, 1] -> 10/3, A[1, 2] -> 10, A[1, 3] -> 20/3, A[1, 4] -> 0, 
  A[1, 5] -> 0, A[1, 6] -> 0, A[2, 0] -> 1, A[2, 1] -> 16/3, 
  A[2, 2] -> 10, A[2, 3] -> 20/3, A[2, 4] -> 0, A[2, 5] -> 0, 
  A[2, 6] -> 0, A[3, 0] -> 2, A[3, 1] -> 4, A[3, 2] -> 0, 
  A[3, 3] -> 0, A[3, 4] -> 0, A[3, 5] -> 0, A[3, 6] -> 0, 
  A[4, 0] -> 1, A[4, 1] -> 2, A[4, 2] -> 0, A[4, 3] -> 0, 
  A[4, 4] -> 0, A[4, 5] -> 0, A[4, 6] -> 0}}

Is it possible in one or two lines to create and assign directly thoose values to the variable A[i,j]?

I have read some questions about how to get values from solve but people often want to renames the variables or only extract a part of the solution so that's probably why the solution takes lines.

Isn't it possible to directly extract the answer in one simple line?

$\endgroup$

1 Answer 1

4
$\begingroup$
rules = 
  {{A[0, 0] -> 0, A[0, 1] -> 0, A[0, 2] -> 1, A[0, 3] -> 4, 
    A[0, 4] -> 5, A[0, 5] -> 2, A[0, 6] -> 0, A[1, 0] -> 0, 
    A[1, 1] -> 10/3, A[1, 2] -> 10, A[1, 3] -> 20/3, A[1, 4] -> 0, 
    A[1, 5] -> 0, A[1, 6] -> 0, A[2, 0] -> 1, A[2, 1] -> 16/3, 
    A[2, 2] -> 10, A[2, 3] -> 20/3, A[2, 4] -> 0, A[2, 5] -> 0, 
    A[2, 6] -> 0, A[3, 0] -> 2, A[3, 1] -> 4, A[3, 2] -> 0, 
    A[3, 3] -> 0, A[3, 4] -> 0, A[3, 5] -> 0, A[3, 6] -> 0, 
    A[4, 0] -> 1, A[4, 1] -> 2, A[4, 2] -> 0, A[4, 3] -> 0, 
    A[4, 4] -> 0, A[4, 5] -> 0, A[4, 6] -> 0}};

Set @@@ rules[[1]];
Definition @ A

definitions

$\endgroup$
1
  • $\begingroup$ Rather than Definition@A, recommend Array[A, {5, 7}, {0, 0}] // MatrixForm $\endgroup$
    – Bob Hanlon
    Commented Jun 17, 2017 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.