Question: Multivariate Taylor Series Expansion Applied to Each Element of a Vector or Matrix

 

This should be a simple question. But sadly I couldn't figure it out on my own

:-(

I know how to get the multivariate Taylor series expansion of a function f of arguments X[1] and X[2], about zero, and to, say, the third order,


mtaylor( f(X[1],X[2]), [X[1],X[2]], 3 );

   f(0, 0) + D[1](f)(0, 0) X[1] + D[2](f)(0, 0) X[2]

        1                      2                             
      + - D[1, 1](f)(0, 0) X[1]  + X[1] D[1, 2](f)(0, 0) X[2]
        2                                                    

        1                      2
      + - D[2, 2](f)(0, 0) X[2]
        2                       

I would now like to apply mtaylor to each element of a Vector/Matrix and store the result in a Vector/Matrix,

My first attempt was to try to use map, something like map(mtaylor,f,x,3); That failed so I tried with seq. I'm nearly there, but I can't get it to work with Vectors/Matrices of arbitrary size.

Here are my test Vectors:

F := X-> Vector([f(X[1],X[2],X[3]),g(X[1],X[2],X[3]),h(X[1],X[2],X[3])]): F(X);

and:

G := X-> Vector([exp(X[1])+X[2],(X[1]-X[2])^3]): G(X);

Here's what I came up with:

TaylorExpand := (F,X,n) -> 
Vector([seq( mtaylor(F(X)[i],[seq(X[j],j=1..100)],n),i=1..nops(F(X)))]):

#Testing
TaylorExpand(F,X,2);
TaylorExpand(G,X,4);

F is the Vector of functions, X is the Vector of arguments of the function, and n is the parameter that determines the length of the expansion of mtaylor.

I constructed the TaylorExpand function from F, which is of dimension 3, and would like it to work for Vectors of any dimension, but it doesn't work for G, which is of dimension 2 rather than 3.

My problem resides in getting the right Vector-dimension into the seq above. nops(F(X)) gives me 3, the correct dimension for test case. But when I use it into my function it seems that nops(F(X)) is already evaluated. I tried nops('F(X)') in an attempt to delay evaluation, but that didn't work either.

Along similar lines I also didn't know how to give seq the dimension of the X-vector. But in this case a workaround that seemed to work was to take a very large number and seq over 1..100.

I'll take any suggestions. It would be useful to me to learn how to work with Vectors/Matrices of unknown dimension, e.g. dealing with nops(F(X)) and an analogous thing to nops(X).

I very much expect that a very concise code exists to do what I'm attempting. Perhaps involving map instead of seq.

I thank you for whatever ideas you may throw at me.

Below are my intermediate steps, showing the logic I tried to apply,


#F(X)[2];
#mtaylor(F(X)[2],[X[1],X[2],X[3]],3);
#seq( mtaylor(F(X)[i],[X[1],X[2],X[3]],3),i=1..3);
#Vector([seq( mtaylor(F(X)[i],[X[1],X[2],X[3]],3),i=1..3)]);
#Vector([seq( mtaylor(F(X)[i],[seq(X[j],j=1..3)],3),i=1..3)]);
#Vector([seq( mtaylor(F(X)[i],[seq(X[j],j=1..3)],3),i=1..nops(F(X)))]);
Vector([seq( mtaylor(F(X)[i],[seq(X[j],j=1..nops(X))],3),i=1..nops(F(X)))]);

Please Wait...