function [Y, X] = smooth_curve(x, y, nodes, n)
   // Smooth an empirical curve using least-square splines
   //
   // Usage:
   //       [Y, X] = smooth_curve(x, y, nodes, n)
   // where
   //       x:     vector of empirical abscissas 
   //       y:     vector of empirical ordinates
   //       nodes: number of lsq_splin nodes
   //       n:     number of points of smoothed data
   //       X:     vector of smoothed curve abscissas
   //       Y:     vector of smoothed curve ordinates
   //   
   // ------------------------------
   // Author: Federico Miyara
   // Date:   2024-09-18 
   
   // Number of input arguments
   rhs = argn(2);
   
   // Set missing arguments
   if rhs<4
      n = 101; 
   end
   if rhs<3
      nodes = 21;
   end
   
   // Distance between abscisas of the proposed nodes
   delta = (max(x) - min(x)) / (nodes - 1);
   // Vector of node abscisas
   xnodo = min(x) + (0:nodes-1)* delta;
   // Get spline parameters
   [ynodo, d] = lsq_splin(x, y, xnodo);
   // Abscissa values where the approximation will be
   // computed
   X = min(x):(max(x)-min(x))/(n-1):max(x);
   // Apply spline to get smoothed ordinates 
   Y = interp(X, xnodo, ynodo, d);
   
endfunction
