# Solve Differential Equations of RLC Circuit Using Laplace Transform

Solve differential equations of an RLC circuit by using Laplace transforms in Symbolic Math Toolbox™ with this workflow. For simple examples on the Laplace transform, see `laplace` and `ilaplace`.

### Definition: Laplace Transform

The Laplace transform of a function $f\left(t\right)$ is

`$\mathit{F}\left(\mathit{s}\right)={\int }_{0}^{\infty }\mathit{f}\left(\mathit{t}\right){\mathit{e}}^{-\mathit{ts}}\mathit{dt}.$`

### Concept: Using Symbolic Workflows

Symbolic workflows keep calculations in the natural symbolic form instead of numeric form. This approach helps you understand the properties of your solution and use exact symbolic values. You substitute numbers in place of symbolic variables only when you require a numeric result or you cannot continue symbolically. For details, see Choose Numeric or Symbolic Arithmetic. Typically, the steps are:

1. Declare equations.

2. Solve equations.

3. Substitute values.

4. Plot results.

5. Analyze results.

### Workflow: Solve RLC Circuit Using Laplace Transform

#### Declare Equations

You can use the Laplace transform to solve differential equations with initial conditions. For example, you can solve resistance-inductor-capacitor (RLC) circuits, such as this circuit.

• Resistances in ohm: ${R}_{1},{R}_{2},{R}_{3}$

• Currents in ampere: ${I}_{1},{I}_{2},{I}_{3}$

• Inductance in henry: $L$

• Capacitance in farad: $C$

• AC voltage source in volts: $E\left(t\right)$

• Capacitor charge in coulomb: $Q\left(t\right)$

Apply Kirchhoff's voltage and current laws to get the following equations.

`$\begin{array}{l}{\mathit{I}}_{1}={\mathit{I}}_{2}+{\mathit{I}}_{3}\\ \mathit{L}\frac{{\mathit{dI}}_{1}}{\mathit{dt}}+{\mathit{I}}_{1}{\mathit{R}}_{1}+{\mathit{I}}_{2}{\mathit{R}}_{2}=0\\ \mathit{E}\left(\mathit{t}\right)+{\mathit{I}}_{2}{\mathit{R}}_{2}-\frac{\mathit{Q}}{\mathit{C}}-{\mathit{I}}_{3}{\mathit{R}}_{3}=0\end{array}$`

Substitute the relation ${I}_{3}=dQ/dt$ (which is the rate of the capacitor being charged) to the above equations to get the differential equations for the RLC circuit.

`$\begin{array}{l}\frac{{\mathit{dI}}_{1}}{\mathit{dt}}-\frac{{\mathit{R}}_{2}}{\mathit{L}}\frac{\mathit{dQ}}{\mathit{dt}}=-\frac{{\mathit{R}}_{1}+{\mathit{R}}_{2}}{\mathit{L}}{\mathit{I}}_{1}\\ \frac{\mathit{dQ}}{\mathit{dt}}=\frac{1}{{\mathit{R}}_{2}+{\mathit{R}}_{3}}\left(\mathit{E}\left(\mathit{t}\right)-\frac{\mathit{Q}}{\mathit{C}}\right)+\frac{{\mathit{R}}_{2}}{{\mathit{R}}_{2}+{\mathit{R}}_{3}}{\mathit{I}}_{1}\end{array}$`

Declare the variables. Because the physical quantities have positive values, set the corresponding assumptions on the variables. Let $E\left(t\right)$ be an alternating voltage of 1 V.

```syms L C I1(t) Q(t) s R = sym('R%d',[1 3]); assume([t L C R] > 0) E(t) = 1*sin(t); % AC voltage = 1 V```

Declare the differential equations.

```dI1 = diff(I1,t); dQ = diff(Q,t); eqn1 = dI1 - (R(2)/L)*dQ == -(R(1)+R(2))/L*I1```
```eqn1(t) =  ```
`eqn2 = dQ == (1/(R(2)+R(3))*(E-Q/C)) + R(2)/(R(2)+R(3))*I1`
```eqn2(t) =  ```

#### Solve Equations

Compute the Laplace transform of `eqn1` and `eqn2`.

`eqn1LT = laplace(eqn1,t,s)`
```eqn1LT =  $s \mathrm{laplace}\left({I}_{1}\left(t\right),t,s\right)-{I}_{1}\left(0\right)+\frac{{R}_{2} \left(Q\left(0\right)-s \mathrm{laplace}\left(Q\left(t\right),t,s\right)\right)}{L}=-\frac{\left({R}_{1}+{R}_{2}\right) \mathrm{laplace}\left({I}_{1}\left(t\right),t,s\right)}{L}$```
`eqn2LT = laplace(eqn2,t,s)`
```eqn2LT =  $s \mathrm{laplace}\left(Q\left(t\right),t,s\right)-Q\left(0\right)=\frac{{R}_{2} \mathrm{laplace}\left({I}_{1}\left(t\right),t,s\right)}{{R}_{2}+{R}_{3}}+\frac{\frac{C}{{s}^{2}+1}-\mathrm{laplace}\left(Q\left(t\right),t,s\right)}{C \left({R}_{2}+{R}_{3}\right)}$```

The function `solve` solves only for symbolic variables. Therefore, to use `solve`, first substitute `laplace(I1(t),t,s)` and `laplace(Q(t),t,s)` with the variables `I1_LT` and `Q_LT`.

```syms I1_LT Q_LT eqn1LT = subs(eqn1LT,[laplace(I1,t,s) laplace(Q,t,s)],[I1_LT Q_LT])```
```eqn1LT =  ${I}_{1,\mathrm{LT}} s-{I}_{1}\left(0\right)+\frac{{R}_{2} \left(Q\left(0\right)-{Q}_{\mathrm{LT}} s\right)}{L}=-\frac{{I}_{1,\mathrm{LT}} \left({R}_{1}+{R}_{2}\right)}{L}$```
`eqn2LT = subs(eqn2LT,[laplace(I1,t,s) laplace(Q,t,s)],[I1_LT Q_LT])`
```eqn2LT =  ${Q}_{\mathrm{LT}} s-Q\left(0\right)=\frac{{I}_{1,\mathrm{LT}} {R}_{2}}{{R}_{2}+{R}_{3}}-\frac{{Q}_{\mathrm{LT}}-\frac{C}{{s}^{2}+1}}{C \left({R}_{2}+{R}_{3}\right)}$```

Solve the equations for `I1_LT` and `Q_LT`.

```eqns = [eqn1LT eqn2LT]; vars = [I1_LT Q_LT]; [I1_LT, Q_LT] = solve(eqns,vars)```
```I1_LT =  $\frac{L {I}_{1}\left(0\right)-{R}_{2} Q\left(0\right)+C {R}_{2} s+L {s}^{2} {I}_{1}\left(0\right)-{R}_{2} {s}^{2} Q\left(0\right)+C L {R}_{2} {s}^{3} {I}_{1}\left(0\right)+C L {R}_{3} {s}^{3} {I}_{1}\left(0\right)+C L {R}_{2} s {I}_{1}\left(0\right)+C L {R}_{3} s {I}_{1}\left(0\right)}{\left({s}^{2}+1\right) \left({R}_{1}+{R}_{2}+L s+C L {R}_{2} {s}^{2}+C L {R}_{3} {s}^{2}+C {R}_{1} {R}_{2} s+C {R}_{1} {R}_{3} s+C {R}_{2} {R}_{3} s\right)}$```
```Q_LT =  $\frac{C \left({R}_{1}+{R}_{2}+L s+L {R}_{2} {I}_{1}\left(0\right)+{R}_{1} {R}_{2} Q\left(0\right)+{R}_{1} {R}_{3} Q\left(0\right)+{R}_{2} {R}_{3} Q\left(0\right)+L {R}_{2} {s}^{2} {I}_{1}\left(0\right)+L {R}_{2} {s}^{3} Q\left(0\right)+L {R}_{3} {s}^{3} Q\left(0\right)+{R}_{1} {R}_{2} {s}^{2} Q\left(0\right)+{R}_{1} {R}_{3} {s}^{2} Q\left(0\right)+{R}_{2} {R}_{3} {s}^{2} Q\left(0\right)+L {R}_{2} s Q\left(0\right)+L {R}_{3} s Q\left(0\right)\right)}{\left({s}^{2}+1\right) \left({R}_{1}+{R}_{2}+L s+C L {R}_{2} {s}^{2}+C L {R}_{3} {s}^{2}+C {R}_{1} {R}_{2} s+C {R}_{1} {R}_{3} s+C {R}_{2} {R}_{3} s\right)}$```

Compute ${I}_{1}$ and $Q$ by computing the inverse Laplace transform of `I1_LT` and `Q_LT`. Simplify the result. Suppress the output because it is long.

```I1sol = ilaplace(I1_LT,s,t); Qsol = ilaplace(Q_LT,s,t); I1sol = simplify(I1sol); Qsol = simplify(Qsol);```

#### Substitute Values

Before plotting the result, substitute symbolic variables by the numeric values of the circuit elements. Let ${R}_{1}=4\phantom{\rule{0.2777777777777778em}{0ex}}\Omega$, ${R}_{2}=2\phantom{\rule{0.2777777777777778em}{0ex}}\Omega$, ${R}_{3}=3\phantom{\rule{0.2777777777777778em}{0ex}}\Omega$, $C=1/4\phantom{\rule{0.2777777777777778em}{0ex}}F$, $L=1.6\phantom{\rule{0.2777777777777778em}{0ex}}H$. Assume that the initial current is ${I}_{1}\left(0\right)=2\phantom{\rule{0.2777777777777778em}{0ex}}A$ and the initial charge is $Q\left(0\right)=2\phantom{\rule{0.2777777777777778em}{0ex}}C$.

```vars = [R L C I1(0) Q(0)]; values = [4 2 3 1.6 1/4 2 2]; I1sol = subs(I1sol,vars,values)```
```I1sol =  $\frac{200 \mathrm{cos}\left(t\right)}{8161}+\frac{405 \mathrm{sin}\left(t\right)}{8161}+\frac{16122 {\mathrm{e}}^{-\frac{81 t}{40}} \left(\mathrm{cosh}\left(\frac{\sqrt{1761} t}{40}\right)-\frac{742529 \sqrt{1761} \mathrm{sinh}\left(\frac{\sqrt{1761} t}{40}\right)}{14195421}\right)}{8161}$```
`Qsol = subs(Qsol,vars,values)`
```Qsol =  $\frac{924 \mathrm{sin}\left(t\right)}{8161}-\frac{1055 \mathrm{cos}\left(t\right)}{8161}+\frac{17377 {\mathrm{e}}^{-\frac{81 t}{40}} \left(\mathrm{cosh}\left(\frac{\sqrt{1761} t}{40}\right)+\frac{1109425 \sqrt{1761} \mathrm{sinh}\left(\frac{\sqrt{1761} t}{40}\right)}{30600897}\right)}{8161}$```

#### Plot Results

Plot the current `I1sol` and charge `Qsol`. Show both the transient and steady state behavior by using two different time intervals: $0\le \mathit{t}\le 15$ and $2\le \mathit{t}\le 25$.

```subplot(2,2,1) fplot(I1sol,[0 15]) title('Current') ylabel('I1(t)') xlabel('t') subplot(2,2,2) fplot(Qsol,[0 15]) title('Charge') ylabel('Q(t)') xlabel('t') subplot(2,2,3) fplot(I1sol,[2 25]) title('Current') ylabel('I1(t)') xlabel('t') text(3,-0.1,'Transient') text(15,-0.07,'Steady State') subplot(2,2,4) fplot(Qsol,[2 25]) title('Charge') ylabel('Q(t)') xlabel('t') text(3,0.35,'Transient') text(15,0.22,'Steady State')```

#### Analyze Results

Initially, the current and charge decrease exponentially. However, over the long term, they are oscillatory. These behaviors are called "transient" and "steady state", respectively. With the symbolic result, you can analyze the result's properties, which is not possible with numeric results.

Visually inspect `I1sol` and `Qsol`. They are a sum of terms. Find the terms by using `children`. Then, find the contributions of the terms by plotting them over `[0 15]`. The plots show the transient and steady state terms.

```I1terms = children(I1sol); I1terms = [I1terms{:}]; Qterms = children(Qsol); Qterms = [Qterms{:}]; figure; subplot(1,2,1) fplot(I1terms,[0 15]) ylim([-0.5 2.5]) title('Current terms') subplot(1,2,2) fplot(Qterms,[0 15]) ylim([-0.5 2.5]) title('Charge terms')```

The plots show that `I1sol` has a transient and steady state term, while `Qsol` has a transient and two steady state terms. From visual inspection, notice `I1sol` and `Qsol` have a term containing the `exp` function. Assume that this term causes the transient exponential decay. Separate the transient and steady state terms in `I1sol` and `Qsol` by checking terms for `exp` using `has`.

`I1transient = I1terms(has(I1terms,'exp'))`
```I1transient =  $\frac{16122 {\mathrm{e}}^{-\frac{81 t}{40}} \left(\mathrm{cosh}\left(\frac{\sqrt{1761} t}{40}\right)-\frac{742529 \sqrt{1761} \mathrm{sinh}\left(\frac{\sqrt{1761} t}{40}\right)}{14195421}\right)}{8161}$```
`I1steadystate = I1terms(~has(I1terms,'exp'))`
```I1steadystate =  $\left(\begin{array}{cc}\frac{200 \mathrm{cos}\left(t\right)}{8161}& \frac{405 \mathrm{sin}\left(t\right)}{8161}\end{array}\right)$```

Similarly, separate `Qsol` into transient and steady state terms. This result demonstrates how symbolic calculations help you analyze your problem.

`Qtransient = Qterms(has(Qterms,'exp'))`
```Qtransient =  $\frac{17377 {\mathrm{e}}^{-\frac{81 t}{40}} \left(\mathrm{cosh}\left(\frac{\sqrt{1761} t}{40}\right)+\frac{1109425 \sqrt{1761} \mathrm{sinh}\left(\frac{\sqrt{1761} t}{40}\right)}{30600897}\right)}{8161}$```
`Qsteadystate = Qterms(~has(Qterms,'exp'))`
```Qsteadystate =  $\left(\begin{array}{cc}-\frac{1055 \mathrm{cos}\left(t\right)}{8161}& \frac{924 \mathrm{sin}\left(t\right)}{8161}\end{array}\right)$```