function [ u, ut, ux, uxx, uxxx ] = kdv_exact_rational ( x, t )

%*****************************************************************************80
%
%% kdv_exact_rational(): exact solution of KDV PDE using a rational function.
%
%  Discussion:
%
%    This solution u(x,t) satisfies the Korteweg-Devries PDE:
%      u' - 6 u ux + uxxx = 0
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 November 2023
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    John D Cook,
%    Rational solution to the Korteweg-De Vries equation,
%    13 November 2023,
%    https://www.johndcook.com/blog/2023/11/13/rational-kdv/
%
%  Input:
%
%    real x: the position.
%
%    real t: the time.
%
%  Output:
%
%    real u, ut, ux, uxx, uxxx:
%    the values of the solution and its derivatives.
%
  u = 6.0 * x * ( x^3 - 24.0 * t ) ...
    / ( x^3 + 12.0 * t )^2;

  ut = - 288.0 * x * ( x^3 - 6.0 * t ) ...
    / ( x^3 + 12.0 * t )^3;

  ux = - 12.0 * ( x^6 - 84.0 * t * x^3 + 144.0 * t^2 ) ...
    / ( x^3 + 12.0 * t )^3;

  uxx =  36.0 * ( x^8 - 192.0 * t * x^5 + 1440.0 * t^2 * x^2 ) ...
    / ( x^3 + 12.0 * t )^4;

  uxxx = - 144.0 * x * ( x^9 - 360.0 * t * x^6 ...
    + 6480.0 * t^2 * x^3 - 8640.0 * t^3 ) ...
    / ( x^3 + 12.0 * t )^5;

  return
end

