Exact interaction of solitary waves for certain nonintegrable equations