2
$\begingroup$

After solving a system of 21 linear equations in 21 variables (called Xi in my code) I got the values for all the 21 variables, in the following way:

{X21 -> 2./q^2, 
 X20 -> (2. - n q X21)/(m q), 
 X19 -> (2. - m n X20 - n (m X20 + n X21))/m^2, 
 X18 -> 2./(l q), 
 X17 -> (2. - l n X18)/(l m), 
 X16 -> 2./l^2, 
 X15 -> (2. - g q X18)/(f q), 
 X14 -> (2. - f n X15 - g (m X17 + n X18))/(f m), 
 X13 -> (2. - g l X16)/(f l), 
 X12 -> (2. - f g X13 - g (f X13 + g X16))/f^2, 
 X11 -> 2./(e q), 
 X10 -> (2. - e n X11)/(e m), 
 X9 -> 2./(e l), 
 X8 -> (2. - e g X9)/(e f), 
 X7 -> 2./e^2, 
 X6 -> (2. - b q X11)/(a q), 
 X5 -> (2. - b (m X10 + n X11) - a n X6)/(a m), 
 X4 -> (2. - b l X9)/(a l), 
 X3 -> (2. - a g X4 - b (f X8 + g X9))/(a f), 
 X2 -> (2. - b e X7)/(a e), 
 X1 -> (2. - a b X2 - b (a X2 + b X7))/a^2}

The latin letters a,b..q are only to be considered as constant parameters. What I would like to do is to express EACH and EVERY value of the variables as a function of only letters. This is possible, because each Xi variable depends on ONLY the variables from X21 to Xi, therefore in principle the problem boils down to a simple substitution.

Nevertheless, I find it difficult to operate this massive substitution in a concise and elegant way, which eventually should produce an array where each entry is given by the value of one variable Xi, expressed in terms of a,b,...q.

$\endgroup$
  • $\begingroup$ "solving a system of 21 linear equations in 21 variables" - I'm either going blind, or you only have 13 solutions. $\endgroup$ – J. M. will be back soon May 12 '16 at 13:35
  • $\begingroup$ @J.M.they are indeed 21. I edited my post to make it clearer $\endgroup$ – johnhenry May 12 '16 at 13:52
  • 4
    $\begingroup$ Solve[Equal @@@ list, First /@ list] should do the trick. $\endgroup$ – J. M. will be back soon May 12 '16 at 13:58
  • 1
    $\begingroup$ As a minor change to @J.M. answer: "Solve[Equal @@@ (list // Rationalize), First /@ list] // Simplify" $\endgroup$ – Bob Hanlon May 12 '16 at 14:05
  • $\begingroup$ @J.M. and Bob Hanlon. I know I am not supposed to do this but +1, these are really great answers! $\endgroup$ – Jack LaVigne May 12 '16 at 14:45
4
$\begingroup$
list = {X21 -> 2./q^2, X20 -> (2. - n q X21)/(m q), 
   X19 -> (2. - m n X20 - n (m X20 + n X21))/m^2, X18 -> 2./(l q), 
   X17 -> (2. - l n X18)/(l m), X16 -> 2./l^2, X15 -> (2. - g q X18)/(f q), 
   X14 -> (2. - f n X15 - g (m X17 + n X18))/(f m), 
   X13 -> (2. - g l X16)/(f l), X12 -> (2. - f g X13 - g (f X13 + g X16))/f^2,
    X11 -> 2./(e q), X10 -> (2. - e n X11)/(e m), X9 -> 2./(e l), 
   X8 -> (2. - e g X9)/(e f), X7 -> 2./e^2, X6 -> (2. - b q X11)/(a q), 
   X5 -> (2. - b (m X10 + n X11) - a n X6)/(a m), X4 -> (2. - b l X9)/(a l), 
   X3 -> (2. - a g X4 - b (f X8 + g X9))/(a f), X2 -> (2. - b e X7)/(a e), 
   X1 -> (2. - a b X2 - b (a X2 + b X7))/a^2};

Starting with J.M.'s comment

Solve[Equal @@@ list, First /@ list] // Simplify

enter image description here

The result is cleaner if the numeric values are rationalized

Solve[Equal @@@ (list // Rationalize), First /@ list] // Simplify

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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