The second Painlevé equation, a related nonautonomous semidiscrete equation, and a limit to the first Painlevé equation: Scalar and matrix cases