Calculate the Rational Canonical Form of a square matrix

Your first check appears to be incorrect. The second one is using a method from the WFR reference page that will not work in general. I blame the author of the function for that.