function fem_surface_rbf ( ns, xs, ys, vs, xmin, xmax, ymin, ymax, filename );

%*****************************************************************************80
%
%% fem_surface_rbf reconstructs the FEM solution from sensor data.
%
%  Discussion:
%
%    A radial basis function approach is used.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    17 April 2019
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer NS, the number of sensors.
%
%    Input, real XS(NS), YS(NS), the sensor coordinates.
%
%    Input, real VS(NS), the sensor readings.
%
%    Input, real XMIN, XMAX, YMIN, YMAX, the argument ranges.
%
%    Input, string FILENAME, the filename to use.
%
  figure ( 'Name', 'RBF interpolant to FEM sensor samples' );
  clf ( );
%
%  Determine the weights for the RBF interpolant.
%
  m = 2;
  xys = [ xs, ys ];
  xys = xys';
  volume = prod ( max ( xys, [], 2 ) - min ( xys, [], 2 ) );
  r0 = ( volume / ns ) ^ ( 1.0 / m );
  w = rbf_weight ( m, ns, xys, r0, @phi1, vs );
%
%  Evaluate the RBF interpolant on a grid.
%
  nix = 21;
  niy = 21;
  xi = linspace ( xmin, xmax, nix );
  yi = linspace ( ymin, ymax, niy );
  [ XI, YI ] = meshgrid ( xi, yi );
  nivec = nix * niy;
  xivec = reshape ( XI, nivec, 1 );
  yivec = reshape ( YI, nivec, 1 );
  xyvec = [ xivec'; yivec' ];
  zvec = rbf_interp ( 2, ns, xys, r0, @phi1, w, nivec, xyvec );
  ZI = reshape ( zvec, nix, niy );

  z_max = max ( zvec );
  z_min = min ( zvec );
  z_min = min ( z_min, 0.0 );
  z_range = z_max - z_min;
  caxis ( [ z_min, z_max ] );
%
%  Plot the RBF interpolant as a surface.
%
  surf ( XI, YI, ZI, 'EdgeColor', 'k' );
  xlabel ( '<--- X --->', 'Fontsize', 16 );
  ylabel ( '<--- Y --->', 'Fontsize', 16 );
  zlabel ( '<---Z(X,Y)--->', 'Fontsize', 16 );
  filename2 = s_escape_tex ( filename );
  datestring = datestr ( datevec ( now ), 0 );
  title ( { filename2; datestring }, 'Fontsize', 16 );
  daspect ( [ 1.0, 1.0, z_range ] );
  colorbar ( );
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s".\n', filename );
  pause ( 5 );
  close ( );

  return
end
