# 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
|
|
4 | 4 | |
5 | 5 | from functional import (diff, derivative, |
6 | 6 | expand, |
7 | | taylor, simplify) |
| 7 | taylor, simplify, implicit_derivative) |
8 | 8 | |
9 | 9 | from functions import (wronskian,jacobian) |
10 | 10 | |
diff --git a/sage/calculus/functional.py b/sage/calculus/functional.py
a
|
b
|
|
32 | 32 | |
33 | 33 | from calculus import SR |
34 | 34 | from sage.symbolic.expression import Expression |
| 35 | from sage.symbolic.function_factory import SymbolicFunction |
35 | 36 | |
36 | 37 | def simplify(f): |
37 | 38 | r""" |
… |
… |
|
433 | 434 | return x.expand(*args, **kwds) |
434 | 435 | except AttributeError: |
435 | 436 | return x |
| 437 | |
| 438 | |
| 439 | def 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 |