BambOo
BambOo

Reputation: 425

Expression manipulation for calculus in julia

I am currently trying some functionalities of Julia regarding symbolic expressions. Coming from Matlab I searched the documentation for symbolic something with little success until I found some info about the expr = :(<content>) notation.

I started with the declaration of my first function : fun1 = :(1-x) which works fine. However, I need to reuse my expression or manipulations of it afterwards.

After searching a bit, I still did not find a way to say e.g fun2 = -fun1. How does one manipulate expressions once they are declared?

EDIT My example statement being a bit restrictive, an additional case would be the construction of a array of expression using pre-declared expresions as in exprarray = [fun1 0 -2*fun2+3]

Upvotes: 3

Views: 92

Answers (1)

MarcMush
MarcMush

Reputation: 1488

you can interpolate expressions with $:

julia> fun1 = :(1-x)
:(1 - x)

julia> fun2 = :(-$fun1)
:(-((1 - x)))

EDIT

The same works for the array :

julia> exprarray = :([$fun1 0 -2*$fun2+3])
:([1 - x 0 -2 * -((1 - x)) + 3])

Upvotes: 3

Related Questions