# Examining the equations of a Differential Op Amp

I want to examine the equations of a differential Operational Amplifier, specifically I want to examine how the tolerances of the resistors affect the resulting differential gain and common mode voltage gain. Specifically in the equations I have I examine the differential gain.

I have two equations, one for the gain and the other for the gain variation.

I want to use Mathematica to find the relation between the two. How can I do this?

The first equation is an equation of 4 resistors. The gain variation is an equation of the 4 same resistors plus another 4 variables which is the tolerances. I want to examine how the two behave and possible plot a curve when varying the above 8 variables.

To be more specific, most of the times one uses resistors of the same tolerance and the resistors come in pairs, meaning that the nominal value of these resistors are the same in pairs (e.g. r1 = r3 and r2 = r4). And this is exactly the occasion I want to study.

The equations that I have are the following:

r3 = r1

r4 = r2

T = 0.05

T1 = T

T2 = T

T3 = T

T4 = T

GainD[r1, r2, r3, r4] = (r4*(r1 + r2) + r2*(r3 + r4))/(2*r1*(r3 + r4))

GainDiv[r1, r2, r3, r4, T1, T2, T3,
T4] = (((((r4/(2 r1 (r3 + r4)) - ((r1 + r2) r4 + r2 (r3 + r4))/(
2 r1^2 (r3 + r4)))*r1*
T1)^2) + (((-((r3 + 2 r4)/(2 r1^2 (r3 + r4))))*r2*
T2)^2) + (((-(1/(2 r1^2 (r3 + r4))) + (r3 + 2 r4)/(
2 r1^2 (r3 + r4)^2))*r3*
T3)^2) + (((3/(2 r1^2 (r3 + r4)^2) - (r3 + 2 r4)/(
r1^2 (r3 + r4)^3))*r4*T4)^2))^(1/2))

GainRes = (GainDiv[r1, r2, r3, r4, T1, T2, T3, T4]/
GainD[r1, r2, r3, r4])*100


How can I find the relationship between GainD and GainDiv?

How can I plot the graph that has GainD and GainRes as the axis while varying r1 r2 r3 and r4?

I need r1 - r3 and r2 - r4 to vary together during the value sweep, meaning to have the same value as r1 = r3 = Ra and r2 = r4 = Rb and plot while varying Ra and Rb as these are the resistors on which the gain depends on.

I am pretty new to Mathematica and it would be indeed a really useful tool when I can examine things like this.

• Welcome to mathematica.stackexchange.com! I sincerely hope the problems in your country do not make life too miserable for you. As to your code, there are several issues: your definition of the two Gain function is missing the Blank-s (_) that should be there (see this). If you want to make plots you need all the variables/parameters/constants to have numerical values. For plotting, look up the Plot function (there are many more; please use the manual for that). – Sjoerd C. de Vries Jul 1 '15 at 15:29
• You state a few contradictory things: you want r1-r3 to vary but you also want that r1=r3=Ra (same for r2 and r4). You can't have both. – Sjoerd C. de Vries Jul 1 '15 at 15:48
• Thank you for your concern and reply, no matter what happens, we still have to do what we do to progress :-). When writing r1-r3 I wanted to denote the pair relationship, that r1 equals r3 and r2 equals r4, not a subtraction, sorry for the confusion. I actually managed to get the graph I wanted, I´ll be posting below my results. Thanks again for your reply, – Eprovatos Jul 2 '15 at 1:03

I've cleaned up your code a bit and although I kept your variable names you should be warned that it is never a good idea to start your variables with an uppercase character as this may conflict with built-in names (that always start with a capital).

r3 = r1;
r4 = r2;
T = 0.05;
T1 = T;
T2 = T;
T3 = T;
T4 = T;
GainD[r1_, r2_, r3_, r4_] := (r4*(r1 + r2) + r2*(r3 + r4))/(2*r1*(r3 + r4))
GainDiv[r1_, r2_, r3_, r4_, T1_, T2_, T3_, T4_] :=
(((((r4/(2 r1 (r3 + r4)) - ((r1 + r2) r4 + r2 (r3 + r4))/
(2 r1^2 (r3 + r4)))*r1*T1)^2) +
(((-((r3 + 2 r4)/(2 r1^2 (r3 + r4))))*r2*T2)^2) +
(((-(1/(2 r1^2 (r3 + r4))) + (r3 + 2 r4)/(2 r1^2 (r3 + r4)^2))*r3*T3)^2) +
(((3/(2 r1^2 (r3 + r4)^2) - (r3 + 2 r4)/(r1^2 (r3 + r4)^3))*r4*T4)^2))^(1/2))


The ratio of GainDiv and GainD (assuming you mean that when you're using the word 'relationship');

GainRes = (GainDiv[r1, r2, r3, r4, T1, T2, T3, T4] / GainD[r1, r2, r3, r4])*100
(* (1/r2)100 r1 √((0.000625 r2^2 (r1 + 2 r2)^2)/(
r1^4 (r1 + r2)^2) +
0.0025 r1^2 (-(r2/r1^2) + r2/(2 r1 (r1 + r2)))^2 +
0.0025 r2^2 (3/(2 r1^2 (r1 + r2)^2) - (r1 + 2 r2)/(
r1^2 (r1 + r2)^3))^2 +
0.0025 r1^2 (-(1/(2 r1^2 (r1 + r2))) + (r1 + 2 r2)/(
2 r1^2 (r1 + r2)^2))^2) *)


Simplifying this (assuming the r's are resistors with positive resistance):

FullSimplify[GainRes, Assumptions -> {r1 > 0, r2 > 0}]
(* (1/(r1 (r1 + r2)^3))100 √(0.000625 (-1. r1 + r2)^2 +
0.000625 r1^2 (r1 + r2)^2 + 0.000625 (r1 + r2)^4 (r1 + 2 r2)^2 +
0.000625 r1^2 (r1 + r2)^4 (r1 + 2. r2)^2) *)


The plot (not really sure whether or not this is what you intended):

ParametricPlot[{GainDiv[r1, r2, r3, r4, T1, T2, T3, T4],
GainD[r1, r2, r3, r4]}, {r1, .1, 100}, {r2, .1, 100},
AspectRatio -> 1/GoldenRatio,
FrameLabel -> {"GainDiv", "GainD", "", ""}] • Hey, thanks a lot for your answer! Although not exactly what I needed it "unlocked" me to go ahead a try what I really wanted. I posted my reply below with my results. When saying that I wanted to find the relationship between GainD and GainDiv, I meant something like an operator without any derivatives, partial or not. The GainDiv is derived from GainD using error propagation, GainD is the differential gain and GainDiv is the gain deviation based on resistor tolerances. Anyhow, your reply was really helpful opening my eyes, thanks again! – Eprovatos Jul 2 '15 at 1:32

So I managed to get what I wanted, thanks a lot for your replies, I am pretty new to Mathematica and they helped a great deal.

Here is my code:

r3 = r1
r4 = r2
T = 0.01
T1 = T
T2 = T
T3 = T
T4 = T

GainD[r1_, r2_, r3_, r4_] := (r4*(r1 + r2) + r2*(r3 + r4))/(2*r1*(r3 + r4))

GainDiv[r1_, r2_, r3_, r4_, T1_, T2_, T3_, T4_] :=
(((((r4/(2 r1 (r3 + r4)) - ((r1 + r2) r4 + r2 (r3 + r4))/(
2 r1^2 (r3 + r4)))*r1*
T1)^2) + (((-((r3 + 2 r4)/(2 r1^2 (r3 + r4))))*r2*
T2)^2) + (((-(1/(2 r1^2 (r3 + r4))) + (r3 + 2 r4)/(
2 r1^2 (r3 + r4)^2))*r3*T3)^2) + (((3/(2 r1^2 (r3 + r4)^2) -
(r3 + 2 r4)/(r1^2 (r3 + r4)^3))*r4*T4)^2))^(1/2))

GainRes = (GainDiv[r1, r2, r3, r4, T1, T2, T3, T4]/GainD[r1, r2, r3, r4])*100

ParametricPlot[{Log10[GainD[r1, r2, r1, r2]], (GainDiv[r1, r2, r1, r2, T1, T2, T3, T4]/
GainD[r1, r2, r1, r2])}, {r1, 100, 1000000}, {r2, 100, 1000000},
PlotRange -> {{-4.2, 4.2}, {T*0.45, T*1.05}},
AspectRatio -> 1/GoldenRatio,FrameLabel -> {"GainD", "GainRes", "", ""}]


The resulting image is like that: The curve is overlapping a bit but I guess it works for my purposes. The good thing is that when plotting, the tolerance is added directly in the PlotRange, so for different resistor tolerances it will automatically resize the y-axis. I can also make the x-axis resize automatically though it needs a bit more coding, still easy to do, might as well post it here when I manage to make it. :-)
I have not found though how to make any axis logarithmic, although I can simply make the value itself logarithmic as I am doing now, so that´s not big harm.