# How can I check if my derivative for an implicit function is correct?

For explicit functions I can calculate the derivative at a certian point using the original function: $$\frac{f(1+0.1) - f(1)}{0.1}$$

And then use $\frac{d}{dx}f(1)$ to check if the function is correct. But what can I do for implicit funcions? how can I calculate the change then compare it with my derivative function

Edit: for example if I was asked to differentiate $f(x)=x^2+\tanh(x)$ and if I am unsure about my answer I could type in on the calculator: $$\frac{f(5+0.000001) - f(5)}{0.000001}$$ and then check my $\frac{d}{dx}f(5)$ they should be approximately equal. My question is if I have an implicit function like $$xy^3=\tan(x+2y)-(x^2-1)$$ and after I differentiate it how can I check if it is correct

• Can you provide us with an example to discuss? – Novice Dec 24 '14 at 9:40
• I added one, hope it is a clear – method Dec 24 '14 at 9:46
• Ok. For this case, if you want to evaluate the derivative at x=5, you also need to have the corresponding y value. In this case, you can find y for x=5.000000001, then apply the derivative quotient as well. Finding the y value for a corresponding given x value for this example will be tedious though. I think you need numerical approximation for this example.:) – Novice Dec 24 '14 at 9:51
• You can first calculate the real derivative for a pair of $(x,y)$ that satisfies the equation, then choose a $\Delta x$, then test if $\left(x+\Delta x, y + \Delta x \frac{dy}{dx}\right)$ approximately satisfies the equation. – peterwhy Dec 24 '14 at 9:54
• If you use the method by peterwhy, you need to find the value of y for that corresponding value of x as well. – Novice Dec 24 '14 at 9:59

You can first calculate the real derivative for a pair of $(x,y)$ that satisfies the equation, then choose a $Δx$, then test if $\left(x+\Delta x,y+\Delta x\frac{dy}{dx}\right)$ approximately satisfies the equation.

For example, looks like $\left(0, -\pi/8\right)$ is a root of your equation. So you can choose $x' = 0.000001$ and find the corresponding $y'$ using the derivative:

\begin{align*} 3xy^2\frac{dy}{dx} + y^3 &= \sec^2(x+2y)\left(1+2\frac{dy}{dx}\right) -2x\\ 3xy^2\frac{dy}{dx} -2\sec^2(x+2y)\frac{dy}{dx} &= \sec^2(x+2y) -2x - y^3\\ \frac{dy}{dx} &= \frac{\sec^2(x+2y) -2x - y^3}{3xy^2 -2\sec^2(x+2y)}\\ \left.\frac{dy}{dx}\right|_{\left(0,-\frac\pi8\right)} &= \frac{2+\frac{\pi^3}{8^3}}{-4} \end{align*}

So let $$y' = -\frac\pi8 +\frac{2+\frac{\pi^3}{8^3}}{-4}\cdot0.000001 \approx -0.392699596839\ldots$$

$$LHS = x'\left(y'\right)^3 = -6.0559372465\ldots×10^{-8}$$ $$RHS = \tan\left(x'+2y'\right)-\left(x'\right)^2 + 1 = -6.056\ldots×10^{-8}$$

And hope it is close enough...

• Do you know how to check a implicit double derivative? – Confuse May 25 '19 at 2:45
• You wrote that "check if $\left(x+\Delta x,y+\Delta x\frac{dy}{dx}\right)$" satisfies the equation. Did you mean $\left(\Delta x,y+\Delta x\frac{dy}{dx}\right)$? – Confuse May 25 '19 at 2:59

Great question - this sort of things shows up all the time when writing code to solve constrained optimization problems.

The standard strategy is as follows. First, you need a mechanism to solve for $y$ given $x$. For example, you could use Newton's method, or bisection search, or whatever. I recommend Newton's method with backtracking linesearch. You can check the correctness of your solver code by plugging $x,y$ into the original equation and verifying that the residual is zero.

Then that complicated solver code is your function $y=f(x)$, and you can check your derivative with finite differences $(f(x+h)-f(x))/h$ with a random direction $h$, like you mention in the original post.

To make sure that your code doesn't converge to a different root when you compute $y_2 = f(x+h)$, use your original $y_1 = f(x)$ as the initial guess in your solver.

Another tip is to choose several different finite difference stepsizes, say $10^{-1}, 10^{-2}, 10^{-3} \dots, 10^{-7}$, and plot the error in the derivative on a log-log plot. The error should linearly decrease until around the square root of machine epsilon - for doubles machine epsilon is around $10^{-15}$, so usually you will see a straight line going down until the step size is around $10^{-7}$, after which point numerical rounding takes over. If your code is working, you should get something that looks like the following plot. • I was coding a simple derivative calculator in c# but had some problems, I look forward the day I will be able to add implicit functions with so much options like limits and graphs – method Dec 24 '14 at 11:10

For an implicit function F(x,y) the formula is:

$$\dfrac{dy}{dx} = - \dfrac{F_x}{F_y} ...(1*)$$

$$F = x\, y^3 + (x^2-1) - \tan ( x+ 2 y)$$

$$F_x = y^3 + 2 x - \sec^2 ( x+ 2 y) ; F_y = 3 x y^2 -2 \sec^2 ( x+ 2 y) ;$$

and plug them in, to evaluate $\frac {dy}{dx}$ at any (x,y).

How does one get this result?

Differentiate F(x,y)= 0 ; Total differential

$$F_x dx + F_y dy = 0.$$

To check by calculation at any point, hold x constant and compute $F_y$ differential the way you stated, then hold y constant and compute $F_x$ same way, use (1*).