Jacobian for nonlinear three tank system. I'm working on the linearization of  a non linear model of a three tank fluid system.
An image for visualisation:

In wich $h_i$ is the water level height of the corresponding tank, and the $k$ factors represent the corresponding valve coefficients.
I have to construct the following jacobian matrix for a set of differential equations. 
$J = \begin{bmatrix}\frac{\partial \dot{h}_1}{\partial h_1} & \frac{\partial \dot{h}_1}{\partial h_2} & \frac{\partial \dot{h}_1}{\partial h_3} \\ \frac{\partial \dot{h}_2}{\partial h_1} & \frac{\partial \dot{h}_2}{\partial h_2} & \frac{\partial \dot{h}_2}{\partial h_3} \\ \frac{\partial \dot{h}_3}{\partial h_1} & \frac{\partial \dot{h}_3}{\partial h_2} & \frac{\partial \dot{h}_3}{\partial h_3}\end{bmatrix}$
The corresponding differential equations for the watertank system are:
$\dot{h}_1=\frac{q_1}{A_T}-\frac{k_{13}A_V\sqrt{2g}}{A_T}\sqrt{|h_1-h_3|}\ sign(h_1-h_3)-\frac{k_{1L}A_V\sqrt{2g}}{A_T}\sqrt{h_1}$
$\dot{h}_2=\frac{q_2}{A_T}-\frac{k_{32}A_V\sqrt{2g}}{A_T}\sqrt{|h_2-h_3|}\ sign(h_2 - h_3)-\frac{k_{2o}A_V\sqrt{2g}}{A_T}\sqrt{h_2}-\frac{k_{3L}A_V\sqrt{2g}}{A_T}\sqrt{h_2}$
$\dot{h}_3=\frac{k_{13}A_V\sqrt{2g}}{A_T}\sqrt{|h_1-h_3|}\ sign(h_1-h_3)+\frac{k_{32}A_V\sqrt{2g}}{A_T}\sqrt{|h_2-h_3|}\ sign(h_2-h_3)-\frac{k_{2L}A_V\sqrt{2g}}{A_T}\sqrt{h_3}$
The derivative of any $sign(h_i - h_j) = 0$ (I think).
Using the product rule we then get:
$\frac{\partial \dot{h}_1}{\partial h_1}=-\frac{h_1-h_3}{2|h_1-h_3|^{\frac{3}{2}}}\ sign(h_1-h_3)\frac{k_{13}A_V\sqrt{2g}}{A_T}-\frac{k_{1L}A_V\sqrt{2g}}{A_T}\frac{1}{2\sqrt{h_1}}$
$\frac{\partial \dot{h}_1}{\partial h_2}=0$ 
$\frac{\partial \dot{h}_1}{\partial h_3}=-\frac{h_3-h_1}{2|h_1-h_3|^{\frac{3}{2}}}\ sign(h_1-h_3)\frac{k_{13}A_V\sqrt{2g}}{A_T}$
$\frac{\partial \dot{h}_2}{\partial h_1}=0$
$\frac{\partial \dot{h}_2}{\partial h_2}=-\frac{h_2-h_3}{2|h_2-h_3|^{\frac{3}{2}}}\ sign(h_2-h_3)\frac{k_{32}A_V\sqrt{2g}}{A_T}-\frac{k_{2o}A_V\sqrt{2g}}{A_T}\frac{1}{2\sqrt{h_2}}-\frac{k_{3L}A_V\sqrt{2g}}{A_T}\frac{1}{2\sqrt{h_2}}$
$\frac{\partial \dot{h}_2}{\partial h_3}=-\frac{h_3-h_2}{2|h_2-h_3|^{\frac{3}{2}}}\ sign(h_2-h_3)\frac{k_{32}A_V\sqrt{2g}}{A_T}$
$\frac{\partial \dot{h}_3}{\partial h_1}=\frac{h_1-h_3}{2|h_1-h_3|^{\frac{3}{2}}}sign(h_1-h_3)\frac{k_{13}A_V\sqrt{2g}}{A_T}$ 
$\frac{\partial \dot{h}_3}{\partial h_2}=\frac{h_2-h_3}{2|h_2-h_3|^{\frac{3}{2}}}\ sign(h_2-h_3)\frac{k_{32}A_V\sqrt{2g}}{A_T}$
$\frac{\partial \dot{h}_3}{\partial h_3}=\frac{h_3-h_1}{2|h_1-h_3|^{\frac{3}{2}}}\ sign(h_1-h_3)\frac{k_{13}A_V\sqrt{2g}}{A_T}+\frac{h_3-h_2}{2|h_2-h_3|^{\frac{3}{2}}}\ sign(h_2-h_3)\frac{k_{32}A_V\sqrt{2g}}{A_T}-\frac{k_{2L}A_V\sqrt{2g}}{A_T}\frac{1}{2\sqrt{h_3}}$
Are these derivatives correct? Thanks in advance,
Mike
 A: The equations
$$
\dot h_1 = c_0 u_1-c_{13} \sqrt{\left| h_1-h_3\right| } \text{sgn}(h_1-h_3)-c_{1L}\sqrt{h_1}\\
\dot h_2 = c_0u_2-c_{32} \sqrt{\left| h_2-h_3\right| } \text{sgn}(h_2-h_3)- (c_{20}+c_{3L})\sqrt{h_2}\\
\dot h_3 = c_{13} \sqrt{\left| h_1-h_3\right| }
 \text{sgn}(h_1-h_3)+c_{32} \sqrt{\left| h_2-h_3\right| } \text{sgn}(h_2-h_3)-c_{2L}
   \sqrt{h_3}
$$
with a variable change can be transformed into a more amenable set. By doing
$$
x_1 = h_1-h_3\\
x_2 = h_2-h_3
$$
we have
$$
\dot x_1 =c_0 u_1 -2 c_{13} \sqrt{\left| x_1\right| } \text{sgn}(x_1)-c_{32} \sqrt{\left| x_2\right| }
   \text{sgn}(x_2)-c_{1L} \sqrt{h_3+x_1}+c_{2L} \sqrt{h_3}\\
\dot x_2=c_0 u_2-c_{13} \sqrt{\left| x_1\right| } \text{sgn}(x_1)-2c_{32} \sqrt{\left|x_2\right| } \text{sgn}(x_2)-(c_{20}+c_{3L}) \sqrt{h_3+x_2}+c_{2L}\sqrt{h_3}\\
\dot h_3= c_{13} \sqrt{\left| x_1\right| } \text{sgn}(x_1)+c_{32}\sqrt{\left|x_2\right| }
   \text{sgn}(x_2)-c_{2L}\sqrt{h_3}
$$
now
$$
\frac{d}{dx}\sqrt{|x|}\mbox{sgn}(x) = \frac{\mbox{sgn}(x)}{2\sqrt{|x|}}
$$
