What is the dissociation percentage of a polybasic organic acid at a certain pH?
Reused my answer to how-to-numerically-model-a-phosphoric-acid-titration-curve, edited for diprotic cases:
First, calculate the common denominator $CD$:
$$a_1 = [\ce{H+}]^2$$
$$a_2 = [\ce{H+}] \cdot K_\mathrm{a1} = a_1 \cdot \frac {K_\mathrm{a1}}{[\ce{H+}]}$$
$$a_3 = K_\mathrm{a1} \cdot K_\mathrm{a2} = a_2 \cdot \frac {K_\mathrm{a2}}{[\ce{H+}]}$$
$$CD = a_1 + a_2 + a_3 $$
.. and then reuse it and its additive terms:
$$[\ce{H2A}]=c_0 \cdot \frac {a_1}{CD}= c_0 \cdot\frac{[\ce{H+}]^2 }{[\ce{H+}]^2 + [\ce{H+}] \cdot K_\mathrm{a1} +  K_\mathrm{a1} \cdot K_\mathrm{a2}}$$
$$[\ce{HA-}]=c_0 \cdot \frac {a_2}{CD}= c_0 \cdot\frac{ [\ce{H+}] \cdot K_\mathrm{a1} }{[\ce{H+}]^2 + [\ce{H+}] \cdot K_\mathrm{a1} +  K_\mathrm{a1} \cdot K_\mathrm{a2}}$$
$$[\ce{A^2-}]=c_0 \cdot \frac {a_3}{CD}=c_0 \cdot \frac{K_\mathrm{a1} \cdot K_\mathrm{a2}}{[\ce{H+}]^2 + [\ce{H+}] \cdot K_\mathrm{a1} +  K_\mathrm{a1} \cdot K_\mathrm{a2}}$$
$c_0$ is the total concentration of respective particular acid forms.
For the general degree of &quot;N-proticity&quot;, the expression terms span from $\ce{[H+]}^N$ to $K_1 \cdot ... \cdot K_\mathrm{aN}$