function R = biharmonic_exact_r2 ( X, Y, a, b, c, d, e, f, g )

%*****************************************************************************80
%
%% biharmonic_exact_r2() evaluates exact biharmonic residual for W(X,Y) #2.
%
%  Discussion:
%
%   Note the formula for W:
%
%  W = ( a      * cos ( g * X ) ...
%      + b      * sin ( g * X ) ...
%      + c * X .* cos ( g * X ) ...
%      + d * X .* sin ( g * X ) ) ... 
%      .*
%      ( e * cosh ( g * Y ) ...
%      + f * sinh ( g * Y ) );
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    01 August 2024
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real X, Y: the coordinates of the points.
%
%    real a, b, c, d, e, f, g: parameters.
%
%  Output:
%
%    real R: the residual evaluated at the points (X,Y).
%
  Wxxxx =  g^3 * ( e * cosh ( g * Y ) + f * sinh ( g * Y ) ) ...
    .* ...
    (     a * g      * cos ( g * X ) ...
    +     b * g      * sin ( g * X ) ...
    +     c * g * X .* cos ( g * X ) ...
    + 4 * c          * sin ( g * X ) ...
    +     d * g * X .* sin ( g * X ) ...
    - 4 * d          * cos ( g * X ) );

  Wxxyy =  - g^3 * ( e * cosh ( g * Y ) + f * sinh ( g * Y ) ) ...
    .* ...
    (     a * g      * cos ( g * X ) ...
    +     b * g      * sin ( g * X ) ...
    +     c * g * X .* cos ( g * X ) ...
    + 2 * c          * sin ( g * X ) ...
    +     d * g * X .* sin ( g * X ) ...
    - 2 * d          * cos ( g * X ) );

  Wyyyy =  g^4 * ( e * cosh ( g * Y ) + f * sinh ( g * Y ) ) ...
    .* ...
    ( a      * cos ( g * X ) ...
    + b      * sin ( g * X ) ...
    + c * X .* cos ( g * X ) ...
    + d * X .* sin ( g * X ) );

  R = Wxxxx + 2.0 * Wxxyy + Wyyyy;

  return
end
