function X = double(S)
%DOUBLE Converts symbolic matrix to MATLAB double.
%   DOUBLE(S) converts the symbolic matrix S to a matrix of double
%   precision floating point numbers.  S must not contain any symbolic
%   variables, except 'eps'.
%
%   See also SYM, VPA.

%   Copyright 1993-2005 The MathWorks, Inc.
%   $Revision: 1.21.4.3.10.1 $  $Date: 2005/01/22 17:23:56 $

if ~isempty(findstr('eps',char(S)))
   S = subs(S,'eps',eps);
end
siz = size(S);
d = 0;
for k = 1:prod(siz)
   c = ['(' char(S(k)) ')'];
   f = find(c<'0' | c>'9');
   d = max(d,max(diff(f)));
end
d = d + 32;
X = reshape(str2num(map2mat(char(maple('evalf',S(:),d)))),siz);

%-------------------------

function r = map2mat(r)
% MAP2MAT Maple to MATLAB string conversion.
%   Inverse of SYM/CHAR.
%   MAP2MAT(r) converts the Maple string r containing
%   matrix, vector, or array to a valid MATLAB string.
%
%   Examples: map2mat(vector([a,b,c,d])
%             returns [a,b,c,d]
%             map2mat(matrix([[a,b], [c,d]])
%             returns [a,b;c,d]
%             map2mat(array([1..x,1..x,1..x],[(1,1,1)=x,...]))
%             returns a 3-D array.

% Deblank.
r(findstr(r,' ')) = [];
% Special case of the empty matrix or vector
if strcmp(r,'vector([])') | strcmp(r,'matrix([])') | ...
   strcmp(r,'array([])')
   r = [];
else
   % Remove matrix, vector, or array from the string.
   r = strrep(r,'matrix([[','['); r = strrep(r,'array([[','[');
   r = strrep(r,'vector([','['); r = strrep(r,'],[',';');
   r = strrep(r,']])',']'); r = strrep(r,'])',']');
end

