Im looking for a very simple example of an algorithm using the capacitor companion model. I have searched online in several different combinations to try to find an example but cant find one that gives me all of the information I need.

I just need to see how to model an RC circuit with a dc voltage input. I have found the equations but I need to see an example of how to implement it, I am trying to implement it in matlab.

Equations I have so far are:

Req = DeltaT/2C or DeltaT/C

Ieq = -2CVo/deltaT - Io

Again I keep finding these equations and terms like "Trapezoidal method" and "Eulers Method" but I cannot find anywhere a simple easy to follow example of how to actually use these equations.

I understand that the equations are using previous terms to calculate the next term but again I cant find example where the problem is worked out.

I understand I could by spice simulation books but this is really just a specific question, I dont want to buy a 50$ book just to find out how to do this one thing.


simulate this circuit – Schematic created using CircuitLab

Also I am assuming that at T = 0, the voltage across the capacitor is O.

  • \$\begingroup\$ One resource I have: dev.hypertriton.com/edacious/trunk/doc/lec.pdf \$\endgroup\$ Nov 28, 2016 at 19:30
  • 1
    \$\begingroup\$ I have a Python implementation for a circuit consisting of capacitors and inductors here. There's some description on how the discretized models were derived including equivalent circuits. The implementation has both trapazoidal and backwards euler integrators. I can explain how these work when I have more time later, but hopefully for now this can be a useful resource. \$\endgroup\$ Nov 28, 2016 at 22:13
  • \$\begingroup\$ @helloworld922 more info would be greatly appreciated I've been scratching my head for a couple of days trying to interpret the sparse information I've found so far. I'll take a look at your code when I get a chance. \$\endgroup\$ Nov 28, 2016 at 22:14

1 Answer 1


An ideal capacitor is modeled using the equation:

\begin{gather} I(t) = C \frac{\partial (V_a(t) - V_b(t))}{\partial t} \end{gather}

where \$V_a\$ and \$V_b\$ are the nodal voltages the capacitor is connected across.

Assuming we don't have an analytical expression for these nodal voltages, we can apply some simple approximations for the derivatives.

For example, the backward's Euler approximation gives (if this looks familiar, it's because we're approximating the slope by a secant line!):

\begin{gather} I(t_1) \approx C \frac{(V_a(t_1) - V_b(t_1)) - (V_a(t_0) - V_b(t_0))}{\Delta t} \end{gather}

Since we are given the initial conditions, we know what \$V_a(t_0)\$ and \$V_b(t_0)\$ are. While everything else is unknown, we have a "quasi-static" problem which can be solved for at \$t_1\$ which no longer has any time derivatives. Re-arranging this approximation, we get:

\begin{gather} \frac{\Delta t}{C} I(t_1) + (V_a(t_0) - V_b(t_0)) = V_a(t_1) - V_b(t_1) \end{gather}

Notice that this equation models a system which looks like this:


simulate this circuit – Schematic created using CircuitLab


\begin{gather} R_{th} = \frac{\Delta t}{C}\\ V_{th} = V_a(t_0) - V_b(t_0) \end{gather}

Now we just need to replace all the capacitors in our circuit with this "quasi-static" capacitor model and we'll have a circuit which we can solve for using the standard techniques for static circuits (modified nodal analysis, mesh analysis, etc.).

Once we know the solution at \$t_1\$, we just rinse and repeat to solve for the solution at \$t_2\$, knowing the solution at \$t_1\$, etc.

More advanced approximations of the time derivative go through the same process, the only difference is the approximation made to get rid of the time derivative is more complicated.

As a last note, if you're using a nodal analysis-like static solver, notice that the approximation circuit introduces a new node. While in theory you could live with this and solve for the voltage at this superfluous node, recall that you can easily replace this Thevanin circuit with its equivalent Norton circuit. This removes the extra unknown, making solving the system of unknowns faster.

As an easy example, take your RC circuit, and replace the capacitor with this quasi-static model:


simulate this circuit

Assuming the capacitor is initially uncharged, then at time \$t_0\$, \$V_{th} = 0\$, so we find that at time \$t_1\$: \begin{gather} V_a(t_1) = \frac{R_{th}}{R + R_{th}} V_s(t_{1}) \end{gather}

To advance from \$t_1\$ to \$t_2\$, now \$V_{th}(t_1) = V_a(t_1)\$. So: \begin{gather} V_a(t_2) = \frac{R_{th}}{R + R_{th}} (V_s(t_{2}) - V_a(t_1))+ V_a(t_1) \end{gather}

You can repeat this processes indefinitely to find what the voltage at \$V_a\$ is at time \$t_{n+1}\$, which is given by:

\begin{gather} V_a(t_{n+1}) = \frac{R_{th}}{R + R_{th}} (V_s(t_{n+1}) - V_{a}(t_n)) + V_a(t_n) \end{gather}

Note that I manually solved the "static" circuits by hand using standard techniques. Explaining how to write one is outside the scope of this question, I refer you to these notes on modified nodal analysis if you want to learn how to do this.

  • \$\begingroup\$ This is pretty much the same information Ive already found. \$\endgroup\$ Nov 29, 2016 at 18:57
  • \$\begingroup\$ The answer I am looking for is just a step by step of how to use these equations in the above circuit. The answer you provided is just a proof of where the equations come from. \$\endgroup\$ Nov 29, 2016 at 19:10
  • \$\begingroup\$ as I mentioned, you just replace all the capacitors in your circuit with this simplified model and march along in time in discrete steps. Once you've plugged this circuit in, you have a "static" circuit which any plain-old circuit solver can solve for you without having to worry about time at all. To advance time, you just update the value of \$V_{th}\$ with the computed capacitor voltage from the previous time step. \$\endgroup\$ Nov 29, 2016 at 19:24
  • \$\begingroup\$ The techniques used here is a standard procedure for numerically solving ordinary differential equations, for which there are lots of resources available online for. \$\endgroup\$ Nov 29, 2016 at 19:26
  • 1
    \$\begingroup\$ The next voltage will not be zero; I've added a simple example for your RC circuit which shows what will happen to the capacitor as time advances. You do need to solve an ODE because that is what this system is mathematically. This technique is just using standard ODE numerical methods. \$\endgroup\$ Nov 29, 2016 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.