Multivariate Taylor Series Problem

Hi,
I was using the package TaylorSeries to find out taylor approximation of a simple multivariate function f(x,y)=x^2+y^2. For the simple approximation around point (0,0) this works fine. However, if i want to expand around any other point e.g (1,1) it gives a wrong estimate. My code is as follows:

using TaylorSeries

RT(Y1, Y2) = Y1^2 + Y2^2 

    Yref1 = 1
    Yref2 = 1
    x, y = set_variables("x y", order=3)
    tseries = RT(x+Yref1, y+Yref2)

    println(tseries)  
The output is :  2.0 + 2.0 x + 2.0 y + 1.0 x² + 1.0 y² + 𝒪(‖x‖⁴)   
whereas I was expecting : 2.0 + 2.0 (x-1) + 2.0 (y-1) + 1.0 (x-1)² + 1.0 (y-1)² + 𝒪(‖x‖⁴)

I think TaylorSeries.jl is correct and your “expected” answer is wrong.

You have a polynomial function, so its Taylor series it just itself, expanded out. In particular, you are giving it:

\mathrm{RT}(x+1, y+1) = (x + 1)^2 + (y + 1)^2 = 2 + 2x + 2y + x^2 + y^2

which matches the TaylorSeries output.

I think the confusion here is that it is expanding in the variables x and y that you gave it, whereas you seem to be expecting an expansion in terms of Y1 - 1 (= x) and Y2 - 1 (= y)?

1 Like

I guess neither were wrong. I just needed to subtract the given Yref from the value at the point where I calculate the series value i.e. at the end of the above code I add

desired_ans=tseries(2-Yref1, 2- Yref2)

if I want to compute the series expansion value at (2,2)