# Simplify part of an expression produced by solve

Mathematica outputs an answer using Solve[] but it is not as simplified as it can be. By manually arranging this expression I know that the parts I've highlighted in yellow can actually be simplified very heavily. I can't use a function like Together[] because I only want to simplify part of the expression (highlighted in yellow)

From manually arranging this I know the whole expression can be written as the following. Notice the highlighted part can be simplified into one simple fraction.

I would be very appreciative if someone can help me with this targeted simplification of what I've highlighted in yellow! And even better yet, it would be great if I could get the expression to output exactly what I've derived by hand (which I guess would involve two separate simplifications?)

I've simplified my code to the following:

rdot = 1/2 epsilon (-(r/Q) + (Fo Sin[\[Alpha]])/(k z))
phidot = (epsilon (-((H R)/(1 - r^2)^(3/2)) - (3 Fo z^2 Cos[\[Alpha]])/r))/(6 k z^3)

sol = Solve[rdot == 0 && alphadot == 0, {sigma, \[Alpha]}]

• If you apply Simplify to the highlighted part (copy it from the output into a new cell), you get something pretty close to your handwritten expression (it seems you have lost a factor) - or is this not what you want? – Lukas Lang Feb 28 '19 at 12:48
• Thank you! This works and gets the same answer but it involves manually selecting what to simplify. Is there a chance this can be done automatically? – Matthew James Feb 28 '19 at 13:56

One can do such kind of things in a fine way. For example, let us make the replacement only in the first solution. Let us define

expr = Plus[Simplify[Take[sol[[1, 1, 2, 2]], 4]],
sol[[1, 1, 2, 2, 5]]],


where sol is your solution. The result is

Now, if you wish to insert it into the original solution,

ReplacePart[sol, {1, 1, 2, 2} -> expr]


then the first line of the result is shown in the image below.

Have fun!

A solution for yellow part:

Simplify[sol[[All, 1, 2, 2, 1 ;; 4]]*sol[[All, 1, 2, 1]]] + sol[[All, 1, 2, 2, 5]]*sol[[All, 1, 2, 1]]