Ask Your Question

Multivariable taylor series with relationship between variables

asked 2014-08-18 22:15:57 +0200

rufus_wilson gravatar image

Let's consider a function f(x,y,z) and the following relationship between the variables:

f(x,y,z) = x+y+z
x << y << z     around 0

I would like the first order Taylor expansion of f around 0. And I would expect this result:

>> taylor(f, (x,0),(y,0),(z,0),1)

But I have :

>> taylor(f, (x,0),(y,0),(z,0),1)

How can I do it?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-12-14 10:05:20 +0200

rufus_wilson gravatar image

updated 2015-12-14 13:49:51 +0200

I have found a way to do it and I'll share the code here in case someone else wants to do it.

Hope it helps someone else.

def TaylorOrdered(func, vartup, order):
    if (not isinstance(vartup,tuple)) or \
            ((not isinstance(vartup[0],tuple)) and (len(vartup)!=3)) or \
            ((isinstance(vartup[0],tuple)) and (len(vartup[0])!=3)):
        print( (not isinstance(vartup,tuple), not isinstance(vartup[0],tuple), len(vartup[0])!=3) )
        raise NotImplementedError, "The second argument should be a tuple of 3-items tuples"
    powrel = {}
    taylist = []
    if not isinstance(vartup[0],tuple):
        powrel[vartup[0]] = Integer(vartup[2])
        taylist.append( (vartup[0], vartup[1]) )
        for i in range(len(vartup)):
            powrel[vartup[i][0]] = Integer(vartup[i][2])
            taylist.append( (vartup[i][0], vartup[i][1]) )
    taytup = tuple(taylist)
    # the added 1 solves the problem of single terms with iterator (numerator and denominator instead of monomials)
    DLtmp = 1+(func.taylor(*taytup).expand())
    if DLtmp.is_symbol() or DLtmp.is_constant() or DLtmp.is_numeric():
        vo = DLtmp;
        vo = func*0
        for t in DLtmp.iterator():
            deg_t = 0
            for v in func.variables():
                if v in powrel.keys():
                    deg_t += powrel[v]*
            if  deg_t <= order :
                vo += t;
    vo = vo.expand()-1;
    return vo

This is the description of the input:

TaylorOrdered(Func, (Var, Point, Rel), Order) # for monovariables
TaylorOrdered(Func, ( (Var1, Point1, Rel1), (Var2, Point2, Rel2), ...), Order) # for multivariables

Here are some examples:

show(TaylorOrdered(sqrt(1+X)+sqrt(1+Y)/h, (X,0,1), 2))
show(TaylorOrdered(sqrt(1+X)+sqrt(1+Y)/h, ((X,0,1),(h,Infinity,-1)), 2))
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2014-08-18 22:15:57 +0200

Seen: 728 times

Last updated: Dec 14 '15