Ticket #12922: 16191.patch

File 16191.patch, 1.9 KB (added by mmarco, 9 years ago)
  • sage/calculus/all.py

    # HG changeset patch
    # User Miguel Marco <mmarco@unizar.es>
    # Date 1336477058 -7200
    # Node ID 79f9eddf7724ca40a9728b599aa126e10e587492
    # Parent  bbea93025f960a168e342438ecab117604931222
    Trac 12922: Added implicit_derivative
    
    diff --git a/sage/calculus/all.py b/sage/calculus/all.py
    a b  
    44
    55from functional import (diff, derivative,
    66                        expand,
    7                         taylor, simplify)
     7                        taylor, simplify, implicit_derivative)
    88
    99from functions import (wronskian,jacobian)
    1010
  • sage/calculus/functional.py

    diff --git a/sage/calculus/functional.py b/sage/calculus/functional.py
    a b  
    3232
    3333from calculus import SR
    3434from sage.symbolic.expression import Expression
     35from sage.symbolic.function_factory import SymbolicFunction
    3536
    3637def simplify(f):
    3738    r"""
     
    433434        return x.expand(*args, **kwds)
    434435    except AttributeError:
    435436        return x
     437
     438
     439def implicit_derivative(Y,X,F,n=1):
     440    """
     441    Computes the n'th derivative of Y with respect to X given implicitly by F.
     442
     443    EXAMPLES:
     444
     445    ::
     446
     447        sage: var('x,y')
     448        (x, y)
     449        sage: implicit_derivative(y,x,cos(x)*sin(y))
     450        sin(x)*sin(y)/(cos(x)*cos(y))
     451        sage: implicit_derivative(y,x,x*y^2,3)
     452        -1/4*(y + 2*y/x)/x^2 + 1/4*(2*y^2/x - y^2/x^2)/(x*y) - 3/4*y/x^3
     453    """
     454    x=SR.symbol('x')
     455    yy=SR.symbol('yy')
     456    y=SymbolicFunction('y',1)(x)
     457    f=SymbolicFunction('f',2)(x,yy)
     458    Fx=f.diff(x)
     459    Fy=f.diff(yy)
     460    G=-(Fx/Fy)
     461    G=G.subs_expr({yy:y})
     462    di={y.diff(x):-F.diff(X)/F.diff(Y)}
     463    R=G
     464    S=G.diff(x,n-1)
     465    for i in range(n+1):
     466        di[y.diff(x,i+1)(x=x)]=R
     467        S=S.subs_expr(di)
     468        R=G.diff(x,i)
     469        for j in range(n+1-i):
     470            di[f.diff(x,i,yy,j)(x=x,yy=y)]=F.diff(X,i,Y,j)
     471            S=S.subs_expr(di)
     472    return S