def collocation_fun(fun, y, p, x, h):
 f = fun(x, y, p)
 y_middle = ((0.5 * (y[:, 1:] + y[:, :(-1)])) - ((0.125 * h) * (f[:, 1:] - f[:, :(-1)])))
 f_middle = fun((x[:(-1)] + (0.5 * h)), y_middle, p)
 col_res = ((y[:, 1:] - y[:, :(-1)]) - ((h / 6) * ((f[:, :(-1)] + f[:, 1:]) + (4 * f_middle))))
 return (col_res, y_middle, f, f_middle)

def collocation_fun ( fun , y , p , x , h ) : f = fun ( x , y , p ) y_middle = ( ( 0.5 * ( y [ : , 1 : ] + y [ : , : ( - 1 ) ] ) ) - ( ( 0.125 * h ) * ( f [ : , 1 : ] - f [ : , : ( - 1 ) ] ) ) ) f_middle = fun ( ( x [ : ( - 1 ) ] + ( 0.5 * h ) ) , y_middle , p ) col_res = ( ( y [ : , 1 : ] - y [ : , : ( - 1 ) ] ) - ( ( h / 6 ) * ( ( f [ : , : ( - 1 ) ] + f [ : , 1 : ] ) + ( 4 * f_middle ) ) ) ) return ( col_res , y_middle , f , f_middle )
evaluate collocation residuals .