2nd derivative of trivariate implicit function I have a trivariate implicit function: $f(x,y,z)=0$ or in more detail: $f(x,y(x),z(x,y(x))=0$
I have the implicit equation for $f(x,y,z)$ and explicit equation for $z(x,y)$, hence I can evaluate the analytical derivatives.  To solve, for any given $x$, I iterate using Newton-Raphson to find $y$.
I am trying to find $\frac{d^2z}{dx^2}$.
I tried to expand this post Second derivative of function of two variables to three variables but the extra $z$ is proving a little tricky.
I started off with:
$\frac{df}{dx}=\frac{\partial f}{\partial x}+\frac{\partial f}{\partial y}.\frac{dy}{dx}+\frac{\partial f}{\partial z}.\frac{dz}{dx}$
from this post: Deriving the Formula of Total Derivative for Multivariate Functions
Which I guess is correct if $z$ is not a function of $y$.
But I don't think this is correct if $z$ is a function of $y$ as well as the $\frac{dz}{dx}$ I get from this is not the same as the derivative calculated numerically.  So before I use this to calculate $\frac{d^2z}{dx^2}$, I need to get the first derivative correct.
Can someone help with the formula?
 A: Firstly, we have \begin{align}\frac{dz}{dx}=\frac{\partial z}{\partial x}+\frac{\partial z}{\partial y}\frac{dy}{dx}\implies\frac{d^2z}{dx^2}&=\frac{\partial}{\partial x}\left(\frac{dz}{dx}\right)+\frac{\partial}{\partial y}\left(\frac{dz}{dx}\right)\frac{dy}{dx}\\&=\frac{\partial}{\partial x}\left(\frac{\partial z}{\partial x}+\frac{\partial z}{\partial y}\frac{dy}{dx}\right)+\frac{\partial}{\partial y}\left(\frac{\partial z}{\partial x}+\frac{\partial z}{\partial y}\frac{dy}{dx}\right)\frac{dy}{dx}\\&=\frac{\partial^2z}{\partial x^2}+\frac{\partial^2z}{\partial x\partial y}\frac{dy}{dx}+\frac{\partial z}{\partial y}\frac{d^2y}{dx^2}+\left(\frac{\partial^2z}{\partial x\partial y}+\frac{\partial^2z}{\partial y^2}\frac{dy}{dx}+0\right)\frac{dy}{dx}\\&=\frac{\partial^2z}{\partial x^2}+2\frac{\partial^2z}{\partial x\partial y}\frac{dy}{dx}+\frac{\partial^2z}{\partial y^2}\left(\frac{dy}{dx}\right)^2+\frac{\partial z}{\partial y}\frac{d^2y}{dx^2}.\end{align} Next, we have \begin{align}\frac{df}{dx}=\frac{\partial f}{\partial x}+\frac{\partial f}{\partial y}\frac{dy}{dx}+\frac{\partial f}{\partial z}\frac{dz}{dx}=0&\implies\frac{dy}{dx}=-\frac{\frac{\partial f}{\partial x}+\frac{\partial f}{\partial z}\frac{dz}{dx}}{\frac{\partial f}{\partial y}}\end{align} whence \begin{align}\small\frac{d^2z}{dx^2}&=z_{xx}-\frac{2z_{xy}}{f_y}\left(f_x+f_z\frac{dz}{dx}\right)+\frac{z_{yy}}{f_y^2}\left(f_x+f_z\frac{dz}{dx}\right)^2-z_y\frac d{dx}\left(\frac{f_x+f_z\frac{dz}{dx}}{f_y}\right)\\&=\small z_{xx}-\frac{2z_{xy}f_x}{f_y}+\frac{z_{yy}f_x^2}{f_y^2}-z_y\frac{d}{dx}\left(\frac{f_x}{f_y}\right)+\left(-\frac{2z_{xy}f_z}{f_y}+\frac{2z_{yy}f_xf_z}{f_y^2}-z_y\frac{d}{dx}\left(\frac{f_z}{f_y}\right)\right)\frac{dz}{dx}-\frac{z_yf_z}{f_y}\frac{d^2z}{dx^2}.\end{align}
