function q2 = q8_exponentiate ( q1 )

%*****************************************************************************80
%
%% q8_exponentiate() exponentiates a quaternion.
%
%  Discussion:
%
%    A quaternion is a quadruplet (A,B,C,D) of real numbers, which
%    may be written as
%
%      Q = A + Bi + Cj + Dk.
%    
%    The exponential of Q can be set by
%      V = sqrt ( B^2 + C^2 + D^2 )
%      e^Q = e^A * ( cos ( ||V|| ) + V/||V|| sin ||V|| )
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    23 July 2018
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real Q1(4), the quaternions to exponentiate.
%
%  Output:
%
%    real Q2(4), the exponential of the quaternion.
%
  v = q1(2:4);
  vnorm = norm ( v );
  q2 = zeros ( 4, 1 );

  q2(1) = cos ( vnorm );
  if ( vnorm ~= 0.0 )
    q2(2:4) = sin ( vnorm ) * v / vnorm;
  end

  q2 = exp ( q1(1) ) * q2;

  return
end
