ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 03 Feb 2011 03:13:06 -0600Graphing derivatives of implicitly given functionshttp://ask.sagemath.org/question/7911/graphing-derivatives-of-implicitly-given-functions/Sorry if this is too elementary.
I want to graph the derivative of a function y that is given implicitly as a function of x. I would appreciate any suggestions. Sat, 29 Jan 2011 10:10:11 -0600http://ask.sagemath.org/question/7911/graphing-derivatives-of-implicitly-given-functions/Answer by kcrisman for <p>Sorry if this is too elementary.</p>
<p>I want to graph the derivative of a function y that is given implicitly as a function of x. I would appreciate any suggestions. </p>
http://ask.sagemath.org/question/7911/graphing-derivatives-of-implicitly-given-functions/?answer=12039#post-id-12039Unfortunately, this is pretty hard to do in Sage. Even this attempt (eventually) fails:
sage: y = function('y',x)
sage: f = y*x==1; f
x*y(x) == 1
sage: f.derivative(x)
x*D[0](y)(x) + y(x) == 0
sage: g = f.derivative(x)
sage: g.operands()[0].operands()[0].operands()[1]
D[0](y)(x)
sage: h = g.solve(g.operands()[0].operands()[0].operands()[1])[0]; h
D[0](y)(x) == -y(x)/x
sage: implicit_plot(h.rhs(),(x,-1,1),(y,-1,1))
<boom>
I don't know that this is easy to fix in general, either, because of course derivatives in implicit functions can be arbitrarily complicated to solve for, and so not necessarily accessible to a computer method. I don't think there are any numerical methods for doing this.Sat, 29 Jan 2011 15:10:27 -0600http://ask.sagemath.org/question/7911/graphing-derivatives-of-implicitly-given-functions/?answer=12039#post-id-12039Answer by DSM for <p>Sorry if this is too elementary.</p>
<p>I want to graph the derivative of a function y that is given implicitly as a function of x. I would appreciate any suggestions. </p>
http://ask.sagemath.org/question/7911/graphing-derivatives-of-implicitly-given-functions/?answer=12041#post-id-12041I agree with kcrisman that this is much harder than it should be. In many cases, though, you can hack around it. One unnecessary problem is that
var("x")
y = function('y')
eq = y(x)+y(x)^2 +sin(x)*y(x)^3
implicit_plot(eq, (x, -5, 5), (y, -10, 10)) # fails
implicit_plot(eq, (x, -5, 5), (y(x), -10, 10)) # fails
doesn't work but should: it doesn't try hard enough to understand y(x), it seems to want a bare y (a variable, not a function).. However, the following does work (more or less):
sage: var("x y_")
(x, y_)
sage: y = function('y')
sage: dydx = diff(y(x),x)
sage: eq = y(x) + y(x)^2 == sin(x)*y(x)^3
sage: sols = solve(diff(eq, x), dydx)
sage: sols
[D[0](y)(x) == -cos(x)*y(x)^3/(3*sin(x)*y(x)^2 - 2*y(x) - 1)]
sage: deq = sols[0].rhs() # get the equation part
sage: deq = deq.subs({y(x): y_})
sage: deq
-y_^3*cos(x)/(3*y_^2*sin(x) - 2*y_ - 1)
sage: implicit_plot(deq, (-5, 5), (-5, 5), plot_points=2000)
There's also another hack I thought of involving replacing dydx with a numerical approximation to it but didn't really explore.
Sat, 29 Jan 2011 15:57:21 -0600http://ask.sagemath.org/question/7911/graphing-derivatives-of-implicitly-given-functions/?answer=12041#post-id-12041Answer by mmarco for <p>Sorry if this is too elementary.</p>
<p>I want to graph the derivative of a function y that is given implicitly as a function of x. I would appreciate any suggestions. </p>
http://ask.sagemath.org/question/7911/graphing-derivatives-of-implicitly-given-functions/?answer=12057#post-id-12057You can try this:
y=function('y',x)
var('x,yy,z')
f=x*y+x^2-y^3*x
ff=f.diff(x).subs({y.diff(x):z,y:yy})
implicit_plot3d(ff,(x,-3,3),(yy,-3,3),(z,-4,4))
This way you avoid the "solve" issue.Thu, 03 Feb 2011 03:13:06 -0600http://ask.sagemath.org/question/7911/graphing-derivatives-of-implicitly-given-functions/?answer=12057#post-id-12057Answer by niles for <p>Sorry if this is too elementary.</p>
<p>I want to graph the derivative of a function y that is given implicitly as a function of x. I would appreciate any suggestions. </p>
http://ask.sagemath.org/question/7911/graphing-derivatives-of-implicitly-given-functions/?answer=12045#post-id-12045Surely there is a way to do this numerically, isn't there? What I mean is that one should be able to write a function which, for a given numerical value of `x`, solves the implicit equation to find the value of the derivative at `x` -- using [`find_root`](http://www.sagemath.org/doc/reference/sage/numerical/optimize.html#sage.numerical.optimize.find_root), perhaps. And then one ought to be able to plot this function.
Of course this won't work for *every* implicitly defined function, but sage's numerics should work for a lot of cases that users actually want.
But I don't know enough about sage symbolics to actually do this. Any takers?Sun, 30 Jan 2011 06:58:03 -0600http://ask.sagemath.org/question/7911/graphing-derivatives-of-implicitly-given-functions/?answer=12045#post-id-12045Answer by Shashank for <p>Sorry if this is too elementary.</p>
<p>I want to graph the derivative of a function y that is given implicitly as a function of x. I would appreciate any suggestions. </p>
http://ask.sagemath.org/question/7911/graphing-derivatives-of-implicitly-given-functions/?answer=12037#post-id-12037I am not sure whether this is what you are looking for
y(x)=sin(x)
plot(diff(sin(x),x),(x,0,pi))Sat, 29 Jan 2011 10:52:21 -0600http://ask.sagemath.org/question/7911/graphing-derivatives-of-implicitly-given-functions/?answer=12037#post-id-12037