# How to substitute diff(y(x),x) with another expression in first and second order implicit differentiation?

I want to use implicit differentiation to find a dy/dx and d2y/dx2. Usually the solution on paper involves finding a replacement for y' that would eventually simplifies the final answer to some simple function of y.

so, for first and second derivative of x^2+y^2=1: there comes an issue where I got sequence instead of expression and I had to convert it to symbolic expression. which ended up with this :

y = function('y')(x);
f = x^2+y^2==1;
print('f is')
show(f)
df=diff(f,x,1);
show(df)

show(equation_2.expand())


I couldn't find a way to substitute the "diff(y,x)" with another expression which only contains y which eventually goes to simplifies the expression to -1/y**3. my workaround this issue was converting the equation to strings and replace the strings with what I wanted.

show(symbolic_expression(str(equation_2.rhs()).replace(str(diff(y(x),x)),str(answer_1[0].rhs()))).substitute(solve(f,x**2)).simplify_full())


if you are looking for the source of the problem. it is from Thomas' calculus 11th edition. Exercise 3.6 no 37-42

Edit - here is a solved example from the book https://pasteboard.co/VXDe8HN0Vytn.png

here is the questions I was referring to: https://pasteboard.co/ecXwH8W1ZRjI.png

Second Edit: ok there my 9.2 sagemath is kinda old. I tried with SageMath 10 on cocalc, the problem is eventhough I'm giving the right code, it doesn't change the derivative with something else.

 y = function('y')(x);
f = x^2+y^2==1;
dydx = solve(diff(f,x,1),diff(y,x,1))
show(dydx[0].rhs())
show(f)
df=diff(dydx[0].rhs(),x,1)
show(df)
df=diff(df,x,1)
df.substitute(diff(y,x,1)==dydx[0].rhs())
d2y = solve(df,diff(y,x,2))
show(d2y)
d2y[0].rhs().substitute(diff(y,x,1)==dydx[0].rhs())
d2y[0].rhs().substitute(x^2==1-y^2)
show(d2y)

edit retag close merge delete

Whene reffering to an external text, please do not assume that your readers have your reference text available. Add a pointer to an available source or quote sufficiently (via pastebin if necessary).

Thank you !

BTW : is this homework ?

( 2023-08-05 17:14:56 +0200 )edit

No, this is not a homework. This is not a hard problem. I just couldn't figure out the problem with type of the output. Sometimes it becomes a free form ring and and sometimes it is a generic sequence. other times something that won't be recognized as symbolic. what ever it is, it might be related to how I defined Y(x).

I am relearning calculus for myself. I just wanted to provide the context of the problem, and by the way I think that most of these problems might be in a course for Differential equations not Calculus I. Cause I remember solving for d2y/dx2 somewhere else.

what level of homework can make me do this :D show(symbolic_expression(str(equation_2.rhs()).replace(str(diff(y(x),x)),str(answer_1[0].rhs()))).substitute(solve(f,x**2)).simplify_full())

( 2023-08-05 18:23:05 +0200 )edit

Sort by ยป oldest newest most voted

What version of Sage do you use ? With 10.1.beta8, the substitution is unproblematic. I changed notations a bit :

sage: reset()
sage: y=function("y")
sage: Eq=x^2+y(x)^2-1 ; Eq
x^2 + y(x)^2 - 1
sage: S1=Eq.diff(x).solve(diff(y(x))) ; S1
[diff(y(x), x) == -x/y(x)]
sage: S2=S1[0].diff(x).subs(S1) ; S2
diff(y(x), x, x) == -x^2/y(x)^3 - 1/y(x)


BTW, neither Sage, Sympy nor Mathematica seem to be able to solve this ODE, at least under this form.

And none of this is necessary to solve for y(x), but I suppose (not having your reference on hand) that it's not the point of the exercise...

EDIT : FWIW, sample implementation in Sagecell...

more

I am using 9.2 on windows

I uploaded the questions that I was referring to here : https://pasteboard.co/ecXwH8W1ZRjI.png I also put a solved example here :

https://pasteboard.co/VXDe8HN0Vytn.png

( 2023-08-05 18:45:26 +0200 )edit

Did you try my solution ? What were the results ?

I am using 9.2 on windows

That may be a bit antique...

Nowadays, the "right" way to use Sage on Windows is to install Linux Windows on WSL (needs an up-to-date Windows 10 or (better) Windows 11). The heroic efforts to maintain the Cygwin port have been abandoned.

I suggest to install from source (tedious but allows for installation of optional packages). See for example this recent answer of Eric Gourgoulhon to a Windows-related question.

HTH,

( 2023-08-05 21:04:21 +0200 )edit

Thanks a lot !

But these are only the questions (and answers) ; what I was reffering to was the method teaching, to see where I could explain better how to "translate" it to Sage.

( 2023-08-05 21:07:04 +0200 )edit

FWIW, sample implementation in Sagecell...

HTH,

( 2023-08-05 21:19:36 +0200 )edit

I tried it also with Sage 10 on cocalc.The function d1d2 doesn't result in (-1/y^3). it instead show's -2x for dy/dx which should be "-x", and differentiates the "-2x" further that results in -2. it should result in " xdiff(y(x), x)/y(x)^2 - 1/y(x))" for the second derivative.

the thing I understood from the book is that the first time taking the implicit derivation, we can reach an equation where dy=dx*f'(x,y) can be of use in two ways. first, getting to dy/dx=f'x for proceeding to higher order differentiation, and second when we substitute dy/dx in f'' with f(x,y) we can simplify f''(x,y,f') to f''(x,y). I hope I am making sense here.

( 2023-08-06 00:25:31 +0200 )edit