Reputation: 1664
My research involves casting problems from scalar formulations to matrix formulations and vice versa. Sometimes finding corresponding matrix patterns and necessary operations to perform on them can get non-obvious and hard to visualize (especially when resulting matrix patterns are large and sparse). To validate my derivations I usually implement both formulations with MATLAB's sym
variables (which allow performing all mathematical operations on them) and check if they are equal.
A trivial example of what I mean:
vec = sym('x',[2,1])
a = (3:4)'
vectorResult = a'*vec
scalar1 = sym('x1')
scalar2 = sym('x2')
scalarResult = a(1)*scalar1 + a(2)*scalar2
isequaln(vectorResult,scalarResult)
ans =
1
So my question is there equivalent alternative for doing this in Julia?
At the moment this is the only thing (aside from the abscence of the MATLAB like IDE) that is preventing me from fully migrating to Julia.
Upvotes: 3
Views: 266
Reputation: 5746
Here is a Julia equivalent form of the above example, with the help of SymPy
package:
using SymPy # load SymPy package, you must Pkg.add("SymPy") before
n=10; # vector length
vec=Sym[Sym(symbol(:x,i)) for i in 1:n]; # create the vector of Sym
a=rand(Int,n); # random vector of factors
vectorResult= transpose(a)*vec; # matrix product
scalarResult=[sum([vec[i]*a[i] for i in 1:n])]; # scaler operation
scalarResult==vectorResult # => true
Upvotes: 3
Reputation: 33259
Base Julia does not ship with support for symbolic computation. For that functionality you can use something like SymPy.jl, which is a package for symbolic computation in Julia (via Python) or Nemo, which is a full computer algebra system based on Julia.
Upvotes: 4