function [ x, status ] = p00_target ( problem, option, nvar, x1, x2, ...
  tar_index, tar_value )

%*****************************************************************************80
%
%% p00_target() computes a solution with a given component value.
%
%  Discussion:
%
%    If we write G(X) = X(TAR_INDEX) - TAR_VALUE, then we are seeking a solution of
%
%      ( F(X) )  =  ( 0 )
%      ( G(X) )     ( 0 )
%
%    We treat the index TAR_INDEX as the parameter to be held fixed.
%
%    Typically, this routine would be called when the user has computed
%    two successive solutions X1 and X2, with the property that the
%
%      X1(TAR_INDEX) < TAR_VALUE < X2(TAR_INDEX)
%
%    or vice-versa.  
%
%    In that case, the appropriate estimate for the starting point X is
%
%      X = ( ( X2(TAR_INDEX) - TAR_VALUE                 ) * X1 
%          + (                 TAR_VALUE - X1(TAR_INDEX) ) * X2 )
%          / ( X2(TAR_INDEX)             - X1(TAR_INDEX) )
%  
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    08 October 2008
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer PROBLEM, the problem index.
%
%    integer OPTION, the option index.
%
%    integer NVAR, the number of variables.
%
%    real X1(NVAR), X2(NVAR), two points satisying F(X) = 0.
%    It is assumed that X1(TAR_INDEX) and X2(TAR_INDEX) bracket the
%    desired value TAR_VALUE.
%
%    integer TAR_INDEX, the index of the entry of X whose value
%    is being specified.
%
%    real TAR_VALUE, the desired value of X(TAR_INDEX).
%
%  Output:
%
%    integer STATUS.
%    nonnegative, the target point was computed.
%    negative, the target point could not be computed.
%
%    real X(NVAR), a point satisfying F(X) = 0 and 
%    X(TAR_INDEX)=TAR_VALUE.
%
  x1 = x1(:);
  x2 = x2(:);

  x = ( ( x2(tar_index) - tar_value                 ) * x1(:)   ...
      + (                 tar_value - x1(tar_index) ) * x2(:) ) ...
      / ( x2(tar_index)             - x1(tar_index) );

  par_index = tar_index;

  [ x, status ] = p00_newton ( problem, option, nvar, x, par_index );

  return
end
