# Solving a system of equations for a fraction

I want to solve a system of equations not for one specific variable but for a fraction of two variables. How can I do that?

I want to solve:

(V2-V1)/R1+V2*s*C1+(V2-V3)*s*C2+(V2-V5)/Rf==0
(V3-V2)*s*C2+V3/R2==0
V4/Ra+(V4-V5)/Rb==0
V3-V4==0


For $V5/V1$

• Take a look at Solve in the documentation, and if you still are stuck, come back and tell us where... – José Antonio Díaz Navas Mar 8 '18 at 13:34
• @JoséAntonioDíazNavas I did, and I can only solve for one specific variabe instead of a fraction – jopi Mar 8 '18 at 13:37

You can do this with a single expression by specifying four variables to solve:

V5/V1 /. Solve[sys, {V5, V1, V3, V2}][[1]]


(C2 R2 (Ra + Rb) Rf s)/( R1 Ra + Ra Rf - C2 R1 R2 Rb s + C1 R1 Ra Rf s + C2 R1 Ra Rf s + C2 R2 Ra Rf s + C1 C2 R1 R2 Ra Rf s^2)

Note however you approach this problem you will get different results depending on which other two symbols you decide to eliminate.

This is looking for:

Elimination for variable V2:

 eq = {(V2 - V1)/R1 + V2*s*C1 + (V2 - V3)*s*C2 + (V2 - V5)/Rf ==
0, (V3 - V2)*s*C2 + V3/R2 == 0, V4/Ra + (V4 - V5)/Rb == 0,
V3 - V4 == 0};
s1 = Eliminate[eq, V2]


Elimination for variable V4:

 s2 = Eliminate[{s1[[1]], s1[[2]], s1[[3]]}, V4]


Solve for: {V5,V1}:

 sol = Solve[{s2[[1]], s2[[2]]}, {V1, V5}]


Fraction of V5/V1:

 (V5 /. sol[[1]])/(V1 /. sol[[1]]) // FullSimplify


$\frac{\text{V5}}{\text{V1}}=\frac{\text{C2} \text{R2} (\text{Ra}+\text{Rb}) \text{Rf} s}{-\text{C2} \text{R1} \text{R2} \text{Rb} s+\text{Ra} \text{Rf} (1+\text{C2} \text{R2} s)+\text{R1} \text{Ra} (1+\text{Rf} s (\text{C1}+\text{C2}+\text{C1} \text{C2} \text{R2} s))}$

EDITED:

One line of code:

eq = {(V2 - V1)/R1 + V2*s*C1 + (V2 - V3)*s*C2 + (V2 - V5)/Rf ==
0, (V3 - V2)*s*C2 + V3/R2 == 0, V4/Ra + (V4 - V5)/Rb == 0,
V3 - V4 == 0};
s1 = Eliminate[eq, V2];
s2 = Eliminate[{s1[[1]], s1[[2]], s1[[3]]}, V4];
sol = Solve[{s2[[1]], s2[[2]]}, {V1, V5}];
frac = (V5 /. sol[[1]])/(V1 /. sol[[1]]) // FullSimplify

• Thanks for your answer, is it possible to do this in one line of code instead for a few lines? – jopi Mar 8 '18 at 14:08

To solve for arbitrary groupings of values, I usually introduce dummy variables and eliminate.

sys = {(V2 - V1)/R1 + V2*s*C1 + (V2 - V3)*s*C2 + (V2 - V5)/Rf == 0,
(V3 - V2)*s*C2 + V3/R2 == 0,
V4/Ra + (V4 - V5)/Rb == 0,
V3 - V4 == 0,
χ == V5/V1};
Solve[sys, {χ}, {V1, V2, V3, V4, V5}]


In this case, χ is defined equivalent to what we're looking for, so we solve for it while eliminating all of the V variables.

you can do it in this way.

V5/V1 /. Solve[eq, {V1, V5}, {V2, V3, V4}]