function R = diff(varargin)
%DIFF   Differentiate.
%   DIFF(S) differentiates a symbolic expression S with respect to its
%   free variable as determined by FINDSYM.
%   DIFF(S,'v') or DIFF(S,sym('v')) differentiates S with respect to v.
%   DIFF(S,n), for a positive integer n, differentiates S n times.
%   DIFF(S,'v',n) and DIFF(S,n,'v') are also acceptable.
%
%   Examples;
%      x = sym('x');
%      t = sym('t');
%      diff(sin(x^2)) is 2*cos(x^2)*x
%      diff(t^6,6) is 720.
%
%   See also INT, JACOBIAN, FINDSYM.

%   Copyright (c) 1993-98 by The MathWorks, Inc.
%   $Revision: 1.11 $  $Date: 1997/11/29 01:05:30 $

if nargin >= 4
   error('DIFF can be called with at most 3 input arguments');
   break;
end

S = sym(varargin{1});
n = 1;
x = [];
for j = 2:nargin
   a = varargin{j};
   if isa(a,'sym')
      x = a.s;
   elseif isvarname(a)
      x = a;
   elseif isa(a,'double') & length(a) == 1
      n = a;
   else
      error(['Do not recognize argument number ' int2str(j)])
   end
end
if isempty(x)
   x = findsym(S,1);
end
if isempty(x)
   R = 0*S;
elseif n == 0
   R = S;
else
   if n > 1
      x = [x '$' int2str(n)];
   end
   R = maple('map','diff',S,x);
end
