ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 25 Aug 2013 13:21:58 +0200Implicit differentiation displays extraneous x variable.https://ask.sagemath.org/question/10393/implicit-differentiation-displays-extraneous-x-variable/The problem is, given `y = 9*x^(1/2) - 2*y^(3/5)`, find dy/dx
The answer is supposed to be `dy/dx = ( 45*y^(2/5) ) / ( 10*x^(1/2)*y^(2/5)+12*x^(1/2) )`
When I enter the following syntax, there is an extraneous character, (x), displayed:
y=function('y',x)
temp=diff(9*x^(1/2) - 2*y^(3/5) - y)
solve (temp,diff(y))
show(solve (temp,diff(y)))
Is it possible to display the answer without showing (x)?
Sun, 28 Jul 2013 10:34:47 +0200https://ask.sagemath.org/question/10393/implicit-differentiation-displays-extraneous-x-variable/Answer by slelievre for <p>The problem is, given <code>y = 9*x^(1/2) - 2*y^(3/5)</code>, find dy/dx
The answer is supposed to be <code>dy/dx = ( 45*y^(2/5) ) / ( 10*x^(1/2)*y^(2/5)+12*x^(1/2) )</code></p>
<p>When I enter the following syntax, there is an extraneous character, (x), displayed:</p>
<pre><code>y=function('y',x)
temp=diff(9*x^(1/2) - 2*y^(3/5) - y)
solve (temp,diff(y))
show(solve (temp,diff(y)))
</code></pre>
<p>Is it possible to display the answer without showing (x)?</p>
https://ask.sagemath.org/question/10393/implicit-differentiation-displays-extraneous-x-variable/?answer=15293#post-id-15293When you do:
sage: y = function('y',x)
sage: temp = diff(9*x^(1/2) - 2*y^(3/5) - y)
sage: a = solve(temp,diff(y)); a
[D[0](y)(x) == 45/2*y(x)^(2/5)/(5*sqrt(x)*y(x)^(2/5) + 6*sqrt(x))]
You see that the result is a list containing one equality.
If I understand correctly you would like to have just "y" instead of "y(x)" in the equation. Probably on the left-hand side you also want to get rid of the "(x)", and let's also have "y'" instead of "`D[0](y)`".
Since you're interested in the displayed result, there are two ways we could go.
One is to try to manipulate the expression itself. It's possible to explore the
equation and get to all the individual pieces, but replacing "y(x)" by "y" in the
symbolic expression is going to be too hard: even when you just ask for "y",
you get "y(x)".
sage: y
y(x)
The second option is to just work on the string. Here is what I would do.
For the left-hand side it's easier to just input y' by hand, and let's throw in the equal sign.
sage: sa = 'y\' = '
Then we can work on the right-hand side.
sage: b = a[0].rhs(); b
45/2*y(x)^(2/5)/(5*sqrt(x)*y(x)^(2/5) + 6*sqrt(x))
Get the latex string.
sage: c = str(latex(b)); c
'\\frac{45 \\, y\\left(x\\right)^{\\frac{2}{5}}}{2 \\, ...'
Now replace.
sage: sb = c.replace('y\\left(x\\right)','y'); sb
'\\frac{45 \\, y^{\\frac{2}{5}}}{2 \\, ...'
Put things together, make it into a latex expression again, and display.
sage: aa = LatexExpr(sa+sb); aa
sage: show(aa)
Wed, 31 Jul 2013 22:37:59 +0200https://ask.sagemath.org/question/10393/implicit-differentiation-displays-extraneous-x-variable/?answer=15293#post-id-15293Answer by viejolitico for <p>The problem is, given <code>y = 9*x^(1/2) - 2*y^(3/5)</code>, find dy/dx
The answer is supposed to be <code>dy/dx = ( 45*y^(2/5) ) / ( 10*x^(1/2)*y^(2/5)+12*x^(1/2) )</code></p>
<p>When I enter the following syntax, there is an extraneous character, (x), displayed:</p>
<pre><code>y=function('y',x)
temp=diff(9*x^(1/2) - 2*y^(3/5) - y)
solve (temp,diff(y))
show(solve (temp,diff(y)))
</code></pre>
<p>Is it possible to display the answer without showing (x)?</p>
https://ask.sagemath.org/question/10393/implicit-differentiation-displays-extraneous-x-variable/?answer=15377#post-id-15377Try this:
sage: g=function('g',x)
sage: var('y')
sage: temp=diff(9*x^(1/2) - 2*g^(3/5) - g)
sage: pretty=solve(temp,diff(g))[0].right().subs({g(x):y})
sage: show(pretty)Sat, 24 Aug 2013 20:55:47 +0200https://ask.sagemath.org/question/10393/implicit-differentiation-displays-extraneous-x-variable/?answer=15377#post-id-15377Comment by nbruin for <p>Try this:</p>
<pre><code>sage: g=function('g',x)
sage: var('y')
sage: temp=diff(9*x^(1/2) - 2*g^(3/5) - g)
sage: pretty=solve(temp,diff(g))[0].right().subs({g(x):y})
sage: show(pretty)
</code></pre>
https://ask.sagemath.org/question/10393/implicit-differentiation-displays-extraneous-x-variable/?comment=17126#post-id-17126Two things:
You may want to define 'gx=function('g',x)' to keep the difference
between the expression 'g(x)' and the bare function 'g' (both get defined by the
statement above)
Also, you may want to write '.subs({gx:y})' which doesn't trigger the
deprecation warning your original code does.
Sun, 25 Aug 2013 13:21:58 +0200https://ask.sagemath.org/question/10393/implicit-differentiation-displays-extraneous-x-variable/?comment=17126#post-id-17126Answer by kcrisman for <p>The problem is, given <code>y = 9*x^(1/2) - 2*y^(3/5)</code>, find dy/dx
The answer is supposed to be <code>dy/dx = ( 45*y^(2/5) ) / ( 10*x^(1/2)*y^(2/5)+12*x^(1/2) )</code></p>
<p>When I enter the following syntax, there is an extraneous character, (x), displayed:</p>
<pre><code>y=function('y',x)
temp=diff(9*x^(1/2) - 2*y^(3/5) - y)
solve (temp,diff(y))
show(solve (temp,diff(y)))
</code></pre>
<p>Is it possible to display the answer without showing (x)?</p>
https://ask.sagemath.org/question/10393/implicit-differentiation-displays-extraneous-x-variable/?answer=15292#post-id-15292I'm not seeing this. Indeed,
sage: latex(solve (temp,diff(y)))
\left[D[0]\left(y\right)\left(x\right) = \frac{45 \, y\left(x\right)^{\frac{2}{5}}}{2 \, {\left(5 \, \sqrt{x} y\left(x\right)^{\frac{2}{5}} + 6 \, \sqrt{x}\right)}}\right]
which shouldn't have this.
Unless you're referring to the `D[0](y)(x)` with the `(x)` part? But remember, you defined `y` to be a function of `x`. So solving for `diff(y)` will still solve for it in this sense. You can't (in Sage) ask for the "type" of a symbolic function to change like that. At least, I think that might be what you are referring to?Wed, 31 Jul 2013 17:52:35 +0200https://ask.sagemath.org/question/10393/implicit-differentiation-displays-extraneous-x-variable/?answer=15292#post-id-15292Answer by Eviatar Bach for <p>The problem is, given <code>y = 9*x^(1/2) - 2*y^(3/5)</code>, find dy/dx
The answer is supposed to be <code>dy/dx = ( 45*y^(2/5) ) / ( 10*x^(1/2)*y^(2/5)+12*x^(1/2) )</code></p>
<p>When I enter the following syntax, there is an extraneous character, (x), displayed:</p>
<pre><code>y=function('y',x)
temp=diff(9*x^(1/2) - 2*y^(3/5) - y)
solve (temp,diff(y))
show(solve (temp,diff(y)))
</code></pre>
<p>Is it possible to display the answer without showing (x)?</p>
https://ask.sagemath.org/question/10393/implicit-differentiation-displays-extraneous-x-variable/?answer=15299#post-id-15299There is a way to change the LaTeX representation of functions, but unfortunately it doesn't survive the trip back from Maxima:
sage: y = function('y', x, print_latex_func=lambda x, args: 'y')
sage: latex(y(x))
y
sage: latex(solve(y, x)[0].lhs())
y\left(x\right)
This should be fixed, although it's probably not trivial to do so.Thu, 01 Aug 2013 14:13:31 +0200https://ask.sagemath.org/question/10393/implicit-differentiation-displays-extraneous-x-variable/?answer=15299#post-id-15299