# Getting a part of a matrix Inverse for later use

I was trying to get an element of a matrix, and use in further computation of my program. Problem was that its not reading the value unless and until I specify it again.

My code is:

     G = k1 Log[k1] + (1.1 + k2) Log[k2] + (k1 + k2) Log[k1 + k2]

(* k1 Log[k1] + (1.1 + k2) Log[k2] + (k1 + k2) Log[k1 + k2]*)

M1 = FullSimplify[{{D[G, {k1, 2}], D[G, k2, k1]}, {D[G, k1, k2],
D[G, {k2, 2}]}}]

(*{{1/k1 + 1/(k1 + k2), 1/(k1 + k2)}, {1/(
k1 + k2), (-1.1 + k2)/k2^2 + 1/(k1 + k2)}}*)

M2 = FullSimplify[{D[G, k1], D[G, k2]}]

(*{2 + Log[k1] + Log[k1 + k2], 2 + 1.1/k2 + Log[k2] + Log[k1 + k2]}*)

M3 =
PowerExpand[Solve[M1.{d1, d2} == -M2, {d1, d2}]]

(*{{d1 -> -((-1. ((-1.1 + k2)/k2^2 + 1/(k1 + k2)) (2. + Log[k1] +
Log[k1 + k2]) + (2. + 1.1/k2 + Log[k2] + Log[k1 + k2])/(
k1 + k2))/(
1/(k1 + k2)^2 -
1. (1/k1 + 1/(k1 + k2)) ((-1.1 + k2)/k2^2 + 1/(k1 + k2)))),
d2 -> -(k1 + k2) (2. + Log[k1] + Log[k1 + k2]) + (
1. (k1 + k2) (1/k1 + 1/(
k1 + k2)) (-1. ((-1.1 + k2)/k2^2 + 1/(k1 + k2)) (2. + Log[k1] +
Log[k1 + k2]) + (2. + 1.1/k2 + Log[k2] + Log[k1 + k2])/(
k1 + k2)))/(
1/(k1 + k2)^2 -
1. (1/k1 + 1/(k1 + k2)) ((-1.1 + k2)/k2^2 + 1/(k1 + k2)))}}*)

G1 = G /. {k1 -> k1 + d1, k2 -> k2 + d2}

(*(d1 + k1) Log[d1 + k1] + (1.1 + d2 + k2) Log[
d2 + k2] + (d1 + d2 + k1 + k2) Log[d1 + d2 + k1 + k2]*)


If observed the code, its not taking d1 and d2. I tried getting the part this way, G1=G/.{k1->k1+M3[[1,1]],k2->k2+M3[[1,2]]} Still it did not work. I just wanted to know the way we need to write the syntax , so that if I call k1->k1+ d1, it would directly gets summed up with k1 for this problem.

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Jan 26 '15 at 14:28
• Others will appreciate it if the code can be copied, pasted directly into Mathematica, and executed. The In/Out tags make that difficult. If you set the option SetOptions[$FrontEnd, ExportMultipleCellsOptions -> {"IncludeCellLabels" -> False}], then they won't be copied from your notebook. Note using $FrontEnd sets it for all sessions. Use \$FrontEndSession if you just want to set it for your current session. Generally people put output inside comments (*...*) so that it won't affect execution when pasted. – Michael E2 Jan 26 '15 at 14:32
• G1 = G /. {k1 -> k1 + d1, k2 -> k2 + d2} /. M3[] – SquareOne Jan 26 '15 at 14:36
• Thank you!! Am new to this.. I did not know it though!! I will try to do that! – Kezia Jan 26 '15 at 14:36
• You're welcome (if you're responding to me). Thanks for editing the question. If you put @ in front the user name, like @MichaelE2, the user will get notified of your response to their comment. (The author is always notified, so I didn't have to do that here.) – Michael E2 Jan 26 '15 at 14:49

After working a lot I came out with an answer for my own question!!! Answer is this way(in coded form),

     M3 =
PowerExpand[Solve[M1.{d1, d2} == -M2, {d1, d2}]]

(* {{d1 -> -((-1. ((-1.1 + k2)/k2^2 + 1/(k1 + k2)) (2. + Log[k1] +
Log[k1 + k2]) + (2. + 1.1/k2 + Log[k2] + Log[k1 + k2])/(
k1 + k2))/(
1/(k1 + k2)^2 -
1. (1/k1 + 1/(k1 + k2)) ((-1.1 + k2)/k2^2 + 1/(k1 + k2)))),
d2 -> -((0.5 (2.2 k1^2 k2 + 3.3 k1 k2^2 + 2. k1^2 k2^2 + 1.1 k2^3 +
4. k1 k2^3 + 2. k2^4 - 1. k1^2 k2^2 Log[k1] -
1. k1 k2^3 Log[k1] + 2. k1^2 k2^2 Log[k2] +
3. k1 k2^3 Log[k2] + k2^4 Log[k2] +
k1^2 k2^2 Log[k1 + k2] + 2. k1 k2^3 Log[k1 + k2] +
k2^4 Log[k1 + k2]))/(-1.1 k1^2 - 1.65 k1 k2 + k1^2 k2 -
0.55 k2^2 + 2. k1 k2^2 + k2^3))}}*)

G1 = G /. {k1 -> k1 + d1, k2 -> k2 + d2} /. M3

(* {(1.1 + k2 - (0.5 (2.2 k1^2 k2 + 3.3 k1 k2^2 + 2. k1^2 k2^2 +

1.1 k2^3 + 4. k1 k2^3 + 2. k2^4 - 1. k1^2 k2^2 Log[k1] -
1. k1 k2^3 Log[k1] + 2. k1^2 k2^2 Log[k2] +
3. k1 k2^3 Log[k2] + k2^4 Log[k2] +
k1^2 k2^2 Log[k1 + k2] + 2. k1 k2^3 Log[k1 + k2] +
k2^4 Log[k1 + k2]))/(-1.1 k1^2 - 1.65 k1 k2 + k1^2 k2 -
0.55 k2^2 + 2. k1 k2^2 + k2^3)) Log[
k2 - (0.5 (2.2 k1^2 k2 + 3.3 k1 k2^2 + 2. k1^2 k2^2 + 1.1 k2^3 +
4. k1 k2^3 + 2. k2^4 - 1. k1^2 k2^2 Log[k1] -
1. k1 k2^3 Log[k1] + 2. k1^2 k2^2 Log[k2] +
3. k1 k2^3 Log[k2] + k2^4 Log[k2] +
k1^2 k2^2 Log[k1 + k2] + 2. k1 k2^3 Log[k1 + k2] +
k2^4 Log[k1 + k2]))/(-1.1 k1^2 - 1.65 k1 k2 + k1^2 k2 -
0.55 k2^2 + 2. k1 k2^2 +
k2^3)] + (k1 - (-1. ((-1.1 + k2)/k2^2 + 1/(k1 + k2)) (2. +
Log[k1] + Log[k1 + k2]) + (
2. + 1.1/k2 + Log[k2] + Log[k1 + k2])/(k1 + k2))/(
1/(k1 + k2)^2 -
1. (1/k1 + 1/(k1 + k2)) ((-1.1 + k2)/k2^2 + 1/(k1 + k2)))) Log[
k1 - (-1. ((-1.1 + k2)/k2^2 + 1/(k1 + k2)) (2. + Log[k1] +
Log[k1 + k2]) + (2. + 1.1/k2 + Log[k2] + Log[k1 + k2])/(
k1 + k2))/(
1/(k1 + k2)^2 -
1. (1/k1 + 1/(k1 + k2)) ((-1.1 + k2)/k2^2 + 1/(
k1 + k2)))] + (k1 +
k2 - (0.5 (2.2 k1^2 k2 + 3.3 k1 k2^2 + 2. k1^2 k2^2 + 1.1 k2^3 +
4. k1 k2^3 + 2. k2^4 - 1. k1^2 k2^2 Log[k1] -
1. k1 k2^3 Log[k1] + 2. k1^2 k2^2 Log[k2] +
3. k1 k2^3 Log[k2] + k2^4 Log[k2] +
k1^2 k2^2 Log[k1 + k2] + 2. k1 k2^3 Log[k1 + k2] +
k2^4 Log[k1 + k2]))/(-1.1 k1^2 - 1.65 k1 k2 + k1^2 k2 -
0.55 k2^2 + 2. k1 k2^2 +
k2^3) - (-1. ((-1.1 + k2)/k2^2 + 1/(k1 + k2)) (2. + Log[k1] +
Log[k1 + k2]) + (2. + 1.1/k2 + Log[k2] + Log[k1 + k2])/(
k1 + k2))/(
1/(k1 + k2)^2 -
1. (1/k1 + 1/(k1 + k2)) ((-1.1 + k2)/k2^2 + 1/(k1 + k2)))) Log[
k1 + k2 - (0.5 (2.2 k1^2 k2 + 3.3 k1 k2^2 + 2. k1^2 k2^2 +
1.1 k2^3 + 4. k1 k2^3 + 2. k2^4 - 1. k1^2 k2^2 Log[k1] -
1. k1 k2^3 Log[k1] + 2. k1^2 k2^2 Log[k2] +
3. k1 k2^3 Log[k2] + k2^4 Log[k2] +
k1^2 k2^2 Log[k1 + k2] + 2. k1 k2^3 Log[k1 + k2] +
k2^4 Log[k1 + k2]))/(-1.1 k1^2 - 1.65 k1 k2 + k1^2 k2 -
0.55 k2^2 + 2. k1 k2^2 +
k2^3) - (-1. ((-1.1 + k2)/k2^2 + 1/(k1 + k2)) (2. + Log[k1] +
Log[k1 + k2]) + (2. + 1.1/k2 + Log[k2] + Log[k1 + k2])/(
k1 + k2))/(
1/(k1 + k2)^2 -
1. (1/k1 + 1/(k1 + k2)) ((-1.1 + k2)/k2^2 + 1/(k1 + k2)))]}*)


When it was getting the part out when I call d1, giving "/.M3" i.e, referring to the Parent matrix, gives the value of d1 stored in M3 matrix.

probably many must be knowing this, Still few may be benefitted out of it!

• It's perfectly ok to accept your own answer. (Click the checkmark below the vote count.) – Michael E2 Apr 27 '15 at 10:27