From: Walter Roberson on
Alan Weiss wrote:
> "Gideon Simpson" <gideon.simpson(a)gmail.com> wrote in message
> <hrkbqu$sui$1(a)fred.mathworks.com>...
>> Alan Weiss <aweiss(a)mathworks.com> wrote in message
>> <hr4j9a$k5i$1(a)fred.mathworks.com>...
>> > On 4/26/2010 1:08 PM, Steven Lord wrote:
>> > > "Gideon Simpson"<gideon.simpson(a)gmail.com> wrote in message
>> > > news:hr4bca$k7g$1(a)fred.mathworks.com...
>> > >> Is it possible to define symbolic variables of arrays?
>> > >>
>> > >> I want to do
>> > >>
>> > >> syms a(1) a(2) a(3)...
>> > >>
>> > >> so that I can compute the jacobian of a vector valued function.

>> jacobian(f, x)
>>
>> I get:
>>
>> [ diff(3*x(1)*x(2) - sin(x(2)) + x(1)^2, x(1)), diff(3*x(1)*x(2) -
>> sin(x(2)) + x(1)^2, x(2))]

> I am not sure it is possible. The basic data type for symbolic variables
> is complex scalar. When you make a vector out of these scalars, I
> believe the scalars should each have a different name. So a vector of
> scalars x = [x1,x2,...,xn], for example, has x(2) = x2. I believe trying
> to do it your way has x(2) essentially undefined.

Symbolic variables can hold symbolic expressions, including symbolic indexing.

What Gideon is asking for is possible in Maple:

> VectorCalculus[Jacobian]([x[1]^2 + 3 * x[1] * x[2] - sin(x[2])],[x[1],x[2]]);

Matrix(1,2,{(1, 1) = 2*x[1]+3*x[2], (1, 2) = 3*x[1]-cos(x[2])}, datatype
= anything,storage = rectangular, order = Fortran_order, shape = [])


> convert(%,list);
[2*x[1]+3*x[2], 3*x[1]-cos(x[2])]


I have never worked with MuPAD (anyone care to donate a Symbolic Toolbox
license? ;-) ), but what I have seen from the documentation suggests that
MuPAD has all of the major basic functionality that Maple has.


Back in the days when Maple was the symbolic engine, what I would have pointed
to would have been the fact that in Maple indexing is by [] and not by (), so
any more complex functionality would have had to have been submitted to the
Maple engine coding with [].

Checking, I see that MuPAD also uses [] for indexing, so my first attempt
would probably be something like,

evalin(symengine, 'jacobian(x[1]^2 + 3 * x[1] * x[2] - sin(x[2])), [x[1],x[2]])')


Once I had the basic functionality working, then I would investigate the
interface between sym() and the symbolic engine to see if I could figure out
how to write the expression at the Matlab level: even if it still turned out
that the final call to jacobian had to be via evalin, it might be nice to
write the polynomial Matlab-style.