# Automating the Equating of Transfer Functions with Symbolic Representations Using SymPy.jl

**URL:** <https://discourse.julialang.org/t/automating-the-equating-of-transfer-functions-with-symbolic-representations-using-sympy-jl/129552>\
**Category:** Signal and Image Processing\
**Tags:** question\
**Created:** [June 2, 2025, 10:21am UTC](https://discourse.julialang.org/t/automating-the-equating-of-transfer-functions-with-symbolic-representations-using-sympy-jl/129552 "2025-06-02T10:21:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![theo.bruelhart](https://avatars.discourse-cdn.com/v4/letter/t/5f9b8f/32.png) [@theo.bruelhart](https://discourse.julialang.org/u/theo.bruelhart)\
**Post date:** [June 2, 2025, 10:21am UTC](https://discourse.julialang.org/t/automating-the-equating-of-transfer-functions-with-symbolic-representations-using-sympy-jl/129552/1 "2025-06-02T10:21:54Z")

</div>

I am currently working on a project where I need to equate a transfer function with its symbolic representations using real components (some resistors and capacitors). Up to this point, I have been manually performing this task using SymPy, specifically employing the `Eq` function (e.g., `exp1 = Eq(x, y)`) and solving for variables (e.g., `solve(exp1, C)`).

I chose SymPy.jl due to some challenges I encountered with the current development state of Symbolics.jl (for reference, please see [Feature Completeness Against SymPy · Issue #59 · JuliaSymbolics/Symbolics.jl · GitHub](https://github.com/JuliaSymbolics/Symbolics.jl/issues/59). However, I am finding the manual assignment of terms to be quite tedious and time-consuming.

Therefore, I am considering automating this process, but I ran into issues when trying to use the method outlined in this article [Extracting All Coefficients in Sympy Using Python 3 - DNMTechs - Sharing and Storing Technology Knowledge](https://dnmtechs.com/extracting-all-coefficients-in-sympy-using-python-3/). Unfortunately, it did not yield the expected results (see below screenshot).

 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/0/50ad40e7624f5bde36032e3ec71d7acc611103cb.png)

Could you please advise me on what I might be doing wrong? Additionally, is there a more efficient way to achieve my goal of automating the equating of transfer functions with their symbolic representations?

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [June 2, 2025, 11:04am UTC](https://discourse.julialang.org/t/automating-the-equating-of-transfer-functions-with-symbolic-representations-using-sympy-jl/129552/2 "2025-06-02T11:04:11Z")

</div>

It’s not 100% clear to me what you are trying to do when you say

> [@theo.bruelhart](#):
>
> equating of transfer functions with their symbolic representations

are you trying to solve for the parameters, C\_1, R\_1,... etc., given a numeric transfer function?

There are some utilities for working with SymPy symbolic transfer functions here

> **[GitHub - JuliaControl/SymbolicControlSystems.jl: C-code generation and an interface between...](https://github.com/JuliaControl/SymbolicControlSystems.jl)**
>
> C-code generation and an interface between ControlSystems.jl and SymPy.jl

---

<div class="post-metadata">

**Author:** ![theo.bruelhart](https://avatars.discourse-cdn.com/v4/letter/t/5f9b8f/32.png) [@theo.bruelhart](https://discourse.julialang.org/u/theo.bruelhart)\
**Post date:** [June 2, 2025, 11:54am UTC](https://discourse.julialang.org/t/automating-the-equating-of-transfer-functions-with-symbolic-representations-using-sympy-jl/129552/3 "2025-06-02T11:54:22Z")

</div>

Your understanding is correct, i.e. I am trying to solve for the parameters C1, R1 given a numeric transfer function.

The below first screenshot shows the symbolic and numeric transfer functions. The symbolic transfer function being of type `Sym{PyCall.PyObject}`.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/9/3946fba34115c85f6468ce9035ee68b13c31d1a8.png)

I then manually assign each symbolic term to its corresponding numerical term (see below), which is a bit tedious.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/c/8c0cf2cd1a90b84ed6dcd2b1e8e59ecc914e90bd.png)

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [June 2, 2025, 12:21pm UTC](https://discourse.julialang.org/t/automating-the-equating-of-transfer-functions-with-symbolic-representations-using-sympy-jl/129552/4 "2025-06-02T12:21:03Z")

</div>

If you have a symbolic transfer function and have loaded `SymbolicControlSystems`, you should be able to call `tf(symbolic_tf)`

```julia
julia> symbolic_tf = w^2 / (s^2 + 2*d*w*s + w^2) # Define symbolic expression
         2       
        w        
─────────────────
           2 2
2⋅d⋅s⋅w + s + w 

julia> G = tf(symbolic_tf) # Convert symbolic expression to TransferFunction
TransferFunction{Continuous, SisoRational{Sym}}
         w^2
---------------------
1*s^2 + 2*d*w*s + w^2

```

and then obtain the coefficients using `ControlSystemsBase.numpoly(G)` or `ControlSystemsBase.numvec(G)` (and `denpoly, denvec` for denominator).

You can see how this is done under the hood here

> <https://github.com/JuliaControl/SymbolicControlSystems.jl/blob/master/src/SymbolicControlSystems.jl#L87C2-L99C4>
