# Symbolically evaluating an in-place function

**URL:** <https://discourse.julialang.org/t/symbolically-evaluating-an-in-place-function/107264>\
**Category:** General Usage\
**Tags:** symbolics\
**Created:** [December 7, 2023, 10:41am UTC](https://discourse.julialang.org/t/symbolically-evaluating-an-in-place-function/107264 "2023-12-07T10:41:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neodym](https://avatars.discourse-cdn.com/v4/letter/n/ba8739/32.png) [@Neodym](https://discourse.julialang.org/u/Neodym)\
**Post date:** [December 7, 2023, 10:41am UTC](https://discourse.julialang.org/t/symbolically-evaluating-an-in-place-function/107264/1 "2023-12-07T10:41:48Z")

</div>

Hi there,

I have an in-place function (RHS of an ODE) and would like to evaluate it with `Symbolics.jl`. Later on, I want to compute its Jacobian.  
However, I cannot figure out how to do that. It appears to not do anything. Certainly, I’m not using the package correctly.

I’ve come up with an MWE

```julia
using Symbolics
@variables x[1:2] y[1:2]

function f!(result, arg)
    result[1] = arg[1] + 2
    result[2] = 2 * arg[2] + arg[1]
    nothing
end

f!(collect(y), x)

```

Executing in the REPL yields

```julia
julia> y
y[1:2]

```

How can I get the symbolic representation of the function?

---

<div class="post-metadata">

**Author:** ![Neodym](https://avatars.discourse-cdn.com/v4/letter/n/ba8739/32.png) [@Neodym](https://discourse.julialang.org/u/Neodym)\
**Post date:** [December 7, 2023, 11:03am UTC](https://discourse.julialang.org/t/symbolically-evaluating-an-in-place-function/107264/2 "2023-12-07T11:03:31Z")

</div>

Nevermind, I figured it out:

```julia
using Symbolics
@variables x[1:2] y[1:2]

function f!(result, arg)
    result[1] = arg[1] + 2
    result[2] = 2 * arg[2] + arg[1]
    nothing
end

yy = collect(y)
f!(yy, x)

```

This gives

```julia
julia> yy
2-element Vector{Num}:
     2 + x[1]
 x[1] + 2x[2]

```

---

<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:** [December 7, 2023, 11:05am UTC](https://discourse.julialang.org/t/symbolically-evaluating-an-in-place-function/107264/3 "2023-12-07T11:05:03Z")

</div>

Using `similar` also works, and is perhaps a bit more clear in terms of intent since you’re not actually using the symbolic `y` variable

```julia
@variables x[1:2]
x = collect(x)
out = similar(x)
f!(out, x)

```
