What is the best way to get the element of a list, which is computed out of substituded variables?
For example one wants to get the first element of the first row of
(a A + a B) /. {a -> 2, A -> {{1, 2}, {3, 4}}, B -> {{8, 7}, {6, 5}}}
Using
(a A + a B)[[1,1]] /. {a -> 2, A -> {{1, 2}, {3, 4}}, B -> {{8, 7}, {6, 5}}}
gives me:
2
I tried something like
elem[x_?MatrixQ, part__: All] := x[[part]];
But this makes the result only more disturbing...
This result should be able to be used in an other expression, where the substituion is done: For example:
temp = (a A+a B)[[1,1]];
temp + 3 /. {a -> 2, A -> {{1, 2}, {3, 4}}, B -> {{8, 7}, {6, 5}}}
Last but not least: Is there also a possibility to hold other expressions? For Example:
temp1[x_] := (x a A + a B)[[1,1]] // Hold;
temp2 = NIntegrate[temp1[x],{0,1,x}] // Hold;
temp2 + 3 /. {a -> 2, A -> {{1, 2}, {3, 4}}, B -> {{8, 7}, {6, 5}}} // ReleaseHold
?
temp = Hold[(a A + a B)[[1, 1]]]; temp + 3 /. {a -> 2, A -> {{1, 2}, {3, 4}}, B -> {{8, 7}, {6, 5}}} // ReleaseHold
? $\endgroup$ – Kuba♦ Oct 17 '14 at 15:51