I don't remember this topic coming up before but at some point
it must be faced since it arises in Calculus 1. AFAIK, SAGE has no routines for
(1) computing the "implicit derivative" y' if y is defined implicitly
by F(x,y)=0,
(2) plotting (x,y) subject to F(x,y)=0.
(1): This is easy for SAGE to compute: y' = - F_x(x,y)/F_y(x,y).
The problem is that it just isn't implemented yet to my knowledge.
How should this be implemented? implicit_derivative(F(x,y),x) or something??
Suggestions?
(2) In the 2d case, it might be possible to tweek matplotlib's
contourplot. It might also be possible to plot the solution to
the 1st order DE y' = - F_x(x,y)/F_y(x,y). Suggestions?
- David Joyner
Is there a need for a special function? I would suggest to use regular
differentiation means.
For inspiration, I just tried this in sympy:
In [1]: g = Function("g")
In [2]: f(g(x), x)
Out[2]: f(g(x), x)
In [3]: e=f(g(x), x)
In [4]: e
Out[4]: f(g(x), x)
In [7]: e.args
Out[7]: (g(x), x)
In [8]: e.diff(x)
Out[8]:
d d d
─────(f(g(x), x))*──(g(x)) + ──(f(g(x), x))
dg(x) dx dx
In [9]: Basic.set_repr_level(1)
Out[9]: 2
In [10]: e.diff(x)
Out[10]: D(f(g(x), x), g(x))*D(g(x), x) + D(f(g(x), x), x)
(you need to use fixed width fonts to see [8], otherwise you'll just see a mess)
But I am not satisfied with the output, especially with
D(f(g(x), x), x)
since it is not clear if it means the total derivative, or just with
respect to the second parameter. Or do you mean something like this:
In [4]: e=f(x)**2+f(x)*x**3-3*f(x)
In [5]: e.diff(x)
Out[5]:
d 3 d d 2
- 3*──(f(x)) + x *──(f(x)) + 2*f(x)*──(f(x)) + 3*x *f(x)
dx dx dx
In [6]: Basic.set_repr_level(1)
Out[6]: 2
In [7]: e.diff(x)
Out[7]: -3*D(f(x), x) + x**3*D(f(x), x) + 2*f(x)*D(f(x), x) + 3*x**2*f(x)
In [9]: solve(e.diff(x).subs(f(x).diff(x), y) == 0, [y])
Out[9]: [3*x**2/(3 - x**3 - 2*f(x))*f(x)]
in [7] I differentiate the implicit definition of f(x), in [9] I solve
for the D(f(x), x) by substituting it for "y" and solving for y.
I cannot now figure out how to do this in Sage, but I am not sure what
the best interface to all of this is. But I think the less functions
(idioms) one needs to remember to do any calculus stuff in Sage, the
better.
Ondrej
To make myself more clear, I'd suggest:
def implicit_derivative(eq, f)
x = f.args[0]
return solve(eq.diff(x), f)
or something like this. At least the goal of the calculus in Sage
should be to support this imho.
Ondrej
It appears that Maxima has an implicit_plot command:
http://maxima.sourceforge.net/docs/manual/en/maxima_55.html
The example seems to work for me with sage -maxima.
Jason
That calls gnuplot though. The option [plot_format,openmath]
(which calls the open source tk/tcl plotter openmath) seems not to
be allowed for implicit_plot.
>
> Jason
>
>
>
> >
>
Here is roughly how to do what you did but in SAGE, in
an example
sage: x = var("x")
sage: y = function("y",x)
sage: F = x^2 + y^2 - 4*x - 1
sage: F.diff(x)
2*y(x)*diff(y(x), x, 1) + 2*x - 4
sage: solve(F.diff(x) == 0, diff(y(x), x, 1))
[diff(y(x), x, 1) == (2 - x)/y(x)]
It seems sympy has some nice symbolic functionality that is missing
in SAGE but this type of example is all I really need. Thanks again.
Thanks, that's what I was looking for. It's actually really simple in Sage.
> It seems sympy has some nice symbolic functionality that is missing
> in SAGE but this type of example is all I really need. Thanks again.
Yes, but Sage.calculus is more robust, SymPy still needs more testing.
Ondrej