Using Operational Amplifiers to solve Ordinary Differential Equations

Written by Guy Fernando

Created Oct 2021 - Last modified Nov 2024

Analogue computers have been used for millennia to describe the behaviour of physical systems in nature. They were first
constructed using mechanical parts such as gears lever and pulleys, but more recently using electrical parts owing to the
popularity of the operational amplifier (op-amp) since the 1940s.

Consider a mass spring damper system - The diagram shows a mass M, held by a spring with spring constant K, and damper
with damping factor B. When the mass is disturbed as described by a forcing function f(t), from experience we know that
the mass will oscillate about a mean position, y. The mass will eventually return to its initial rest position due to the
resistance present in the damper.

The dynamics of a mass spring damper system can be mathematically modelled as a 2nd order Ordinary Differential Equation (ODE).

\( \begin{aligned}
M \frac{ d^{2}y }{dt^{2} } + B \frac{dy}{dt} + Ky = f(t)
\end{aligned} \)

This ODE or in general any ODE can be solved using a combination of the op-amp building blocks as described below.

With an op-amp configured in differential mode, signals can be applied simultaneously to both the inverting and non-inverting
inputs of the op-amp, to perform addition and subtraction operations. Extra adding or subtracting terms can added by simply
adding more input resistors to the inputs of the op-amp. We will use this adder-subtractor building block later for simulating
the differential equation circuit.

\( \begin{aligned}
y = (V1 + V2) - (V3 + V4)
\end{aligned} \)

Multiplication and division using op-amps is more involved than the other op-amp building blocks presented here. One technique
to achieve this is to exploit the exponential nature of semiconductors that occurs around their non-linear region “knee point”
for specifically producing logarithmic and anti-logarithmic converters. Transistors are chosen here in favour of diodes as
they typically exhibit a wider decade current logging range.

We know that a log of a product is the sum of the log factors, and that the log of a quotient is the difference of the log
factors. By taking the log of each input signal, combining them, then finally taking the anti-log, an adequate multiplier-divider
can be realized. Op-amps U1, U2 and U3 are configured as log amplifiers, while U4 is configured as an antilog amplifier. It is
worth remembering the limitations of this circuit as a single quadrant device only, and thus only functions correctly with
positive input voltages.

\( \begin{aligned}
y = antilog[log(V1) + log(V2) - log(V3)] = \frac{ V1 . V2 }{ V3 }
\end{aligned} \)

An op-amp integrator is surprisingly simple and can be produced with remarkably few components as shown in the diagram. The
circuit acts as a basic integrator, since all current sourced from V arriving at the inverting input of the op-amp must
exit through the feedback path, and the voltage across the capacitor is proportional to the integral with respect to time
of the capacitor charging current. We will use this integrator building block later for simulating the differential equation
circuit.

\( \begin{aligned}
y = - \frac{1}{CR} \int V dt
\end{aligned} \)

The op-amp differentiator is obtained by swapping the position of the resistor and capacitor in the integrator circuit.
The circuit acts as a basic differentiator, since the input signal is applied through a capacitor there is current flow to
the amplifier summing point and a non-zero output voltage only when the input voltage V changes. The use of a differentiator
is limited due to inherent noise problems, and inferior performance when compared to the integrator, and so is less used
in analogue computing applications.

\( \begin{aligned}
y = -CR.\frac{dV}{dt}
\end{aligned} \)

By combining the adder-subtractor and integrator op-amp building blocks it is possible to simulate this ODE.

\( \begin{aligned}
M \frac{ d^{2}y }{dt^{2} } + B \frac{dy}{dt} + Ky = f(t)
\end{aligned} \)

Rearranging the original equation with the second order derivative as the subject, and referring to the right hand side
of the equation.

\( \begin{aligned}
\frac{ d^{2}y }{dt^{2} } = \big(\frac{B}{M}\big) \frac{dy}{dt} + \big(\frac{K}{M}\big) y - \frac{f(t)}{M}
\end{aligned} \)

Since the equation is 2nd order we will require two integrators.

The first two terms (damping factor B / M and spring constant K / M) require summation; the third term (forcing function
F(t) / M ) will require subtraction. This is achieved by op-amp U1 which serves as a combined adder-subtractor and the
first integrator. U2 is the second integrator, and U3 an inverter used to restore the sense of the final output. Remember
that both the adder-subtractor and inverter blocks reverse the sense of the signal between their input and output.

Assuming the input forcing function f(t) applied is a step function, corresponding to the mass physically being pushed
down and then letting go. The graph here plots the output of the op-amp simulator if observed using an oscilloscope.
By adjusting the mass M, damping factor B and spring constant K, the response shown on the graph can be made to be
under-damped, critically-damped or over-damped.

Adjust the Constants below to Change the Output Damping Response:

(kg) :

(Nm/s) :

(N/m) :

Calculated Component Values:

C | R | R1 | R2 | R3 |
---|---|---|---|---|

1.00 µF | 1.00 MΩ | MΩ | MΩ | MΩ |

` ````
// 2nd order homogeneous ODE for a mass-spring-damper.
// Guy Fernando (2021)
// Compute M.y" + B.y' + K.y = 0
var f = function (m, b, k) {
return function (x, y) {
return [y[1], -((b * y[1]) + (k * y[0])) / m];
}
}
// Use ODEX to solve the ODE.
var s = new Solver(2);
s.denseOutput = true;
s.absoluteTolerance = s.relativeTolerance = 1e-10;
var xValues = [];
var yValues = [];
const M = 1.0, B = 0.5, K = 5.0;
s.solve(f(M, B, K), 0, [1, 0], 10, s.grid(0.01, function (x, y) {
xValues.push(x);
yValues.push(y[0]);
}));
// Render the graph using Plotly.js.
const config = { responsive: true }
const data = [{
x: xValues,
y: yValues,
type: 'line'
}];
Plotly.newPlot('plot', data, null, config);
```

Today digital computers are chosen in favour of op-amps for calculating and solving ODEs. As an example of solving the
ODE digitally, the same mass spring damper system as modelled above using op-amps is shown here modelled in the JavaScript
listing. This code is actually running on this web page for plotting the graph above.

The code here uses the ODEX library odex.js ported from the originally version written in FORTRAN. (I had to modify the
library slightly such that it is not dependent on Node.js for client-side use with web browsers.) The ODEX library
implementation is based on the Bulirsch–Stoer algorithm for the numeric solution of ODEs obtaining high accuracy with
comparatively little computational effort.

Analogue computers have gone out of fashion in recent decades since the introduction of the modern digital computer.
Performing calculations in the digital domain is more favorable because of the deterministic accuracy, their convenience
of use, and the vast selection of mathematical based software libraries now widely available.

In spite of this modern-day competition, analogue computers can still present a viable alternative for certain applications.
By combining various op-amp building blocks together, complex mathematical problems can be solved with only a few op-amps
and a few additional passive components. Providing the application does not require high numerical accuracy or high
numerical range, computation in the analogue domain will outperform digital computation on calculation speed, and for a
relatively low expense.

This website is powered using ultra low power green locally based servers.

Copyright © i4cy 2000-2024. All rights reserved.