Ask Your Question

rufus_wilson's profile - activity

2020-12-02 01:44:21 +0100 received badge  Famous Question (source)
2016-01-28 18:30:55 +0100 received badge  Notable Question (source)
2015-12-14 13:49:51 +0100 received badge  Editor (source)
2015-12-14 12:03:41 +0100 answered a question Multivariable taylor series with relationship between variables

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)):
        show(vartup[0])
        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]) )
    else:
        for i in range(len(vartup)):
            powrel[vartup[i][0]] = Integer(vartup[i][2])
            taylist.append( (vartup[i][0], vartup[i][1]) )
    taylist.append(order+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;
    else:
        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]*t.degree(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))
2015-12-14 10:05:29 +0100 received badge  Scholar (source)
2015-12-14 09:58:26 +0100 received badge  Popular Question (source)
2014-08-18 22:15:57 +0100 asked a question Multivariable taylor series with relationship between variables

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)
z

But I have :

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

How can I do it?