# Get left hand side of SymPy equations

**URL:** <https://discourse.julialang.org/t/get-left-hand-side-of-sympy-equations/59694>\
**Category:** General Usage\
**Tags:** sympy\
**Created:** [April 20, 2021, 9:17pm UTC](https://discourse.julialang.org/t/get-left-hand-side-of-sympy-equations/59694 "2021-04-20T21:17:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fms-1988](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fms-1988/32/20275_2.png) [@fms-1988](https://discourse.julialang.org/u/fms-1988)\
**Post date:** [April 20, 2021, 9:17pm UTC](https://discourse.julialang.org/t/get-left-hand-side-of-sympy-equations/59694/1 "2021-04-20T21:17:38Z")

</div>

I have a vector of equations:

```julia
using SymPy
θ,ω,dθ,dω,b,c = symbols("θ,ω,\\dot{θ},\\dot{ω},b,c")
f1 = Eq(dθ,ω)
f2 = Eq(dω,-b*ω - c* sin(θ))
eqns = [f1;f2]

```

out:

\left[\begin{array}{c} \dot{θ} = ω \\ \dot{ω} = -b\*ω - c\*sin(θ) \\ \end{array} \right]

I want to return only the first side of the equality.  
The code I use for this is as follows:

```julia
sys_vec = function (sys,col)
vec = zeros(Sym, (size(sys, 1),1)) #vetor variaveis
    for i in 1:size(sys, 1)
        vec[i,1] = [var for var in sys[i].args][col]
    end
    return vec
end

sys_vec(eqns,1)

```

out:

\left[\begin{array}{c} \dot{θ} \\ \dot{ω} \\ \end{array} \right]

Would there be a way to simplify it? Without using the loop directly?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [April 20, 2021, 10:12pm UTC](https://discourse.julialang.org/t/get-left-hand-side-of-sympy-equations/59694/2 "2021-04-20T22:12:34Z")

</div>

Did you try:

```julia
[eqns[1].lhs; eqns[2].lhs]

or better:
[x.lhs for x in eqns]

```

---

<div class="post-metadata">

**Author:** ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)\
**Post date:** [April 21, 2021, 12:06am UTC](https://discourse.julialang.org/t/get-left-hand-side-of-sympy-equations/59694/3 "2021-04-21T00:06:31Z")

</div>

@rafael.guerra has exactly the right answer in general, as this just calls the always available SymPy method. In this case, there are also exports for `rhs` and `lhs` ([SymPy.jl/mathfuns.jl at master · JuliaPy/SymPy.jl · GitHub](https://github.com/JuliaPy/SymPy.jl/blob/master/src/mathfuns.jl#L219)) that replicate the same, so `lhs.(eqns)` should work as desired.

---

<div class="post-metadata">

**Author:** ![fms-1988](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fms-1988/32/20275_2.png) [@fms-1988](https://discourse.julialang.org/u/fms-1988)\
**Post date:** [April 21, 2021, 10:37am UTC](https://discourse.julialang.org/t/get-left-hand-side-of-sympy-equations/59694/4 "2021-04-21T10:37:09Z")

</div>

Thank you very much @rafael.guerra .  
I’m learning the Julia language, and I think the interaction between Julia and Sympy is confusing me a little.

---

<div class="post-metadata">

**Author:** ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)\
**Post date:** [April 21, 2021, 11:22am UTC](https://discourse.julialang.org/t/get-left-hand-side-of-sympy-equations/59694/5 "2021-04-21T11:22:57Z")

</div>

Yes, it can be confusing. Basically, (using “sympy” for the Python library, and “SymPy” for the Julia package):

- For as many generic functions from Julia as possible, methods are defined for symbolic values and called as `fn(obj, ...)`
- sympy methods and properties for SymPy objects are called as in sympy, through `obj.fn(...)` or `obj.prop`
- Some, not so many, sympy methods and properties, such as `lhs` and `rhs`, `solve`,…, have Julia counterparts and are called as `fn(obj,...)`
- Constructors and other calls from sympy may be called from the exported `sympy` object as `sympy.Constructor(...)`, conversions from Julia objects follow rules set up within `PyCall`.

---

<div class="post-metadata">

**Author:** ![fms-1988](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fms-1988/32/20275_2.png) [@fms-1988](https://discourse.julialang.org/u/fms-1988)\
**Post date:** [April 21, 2021, 7:45pm UTC](https://discourse.julialang.org/t/get-left-hand-side-of-sympy-equations/59694/6 "2021-04-21T19:45:07Z")

</div>

Very enlightening.
