%% Display and Evaluate Symbolic Expression
% Create a string S representing a symbolic expression.

S = "exp(2*pi*i)";

% Create another string symstr that contains S.

symstr = "1 + S + S^2 + cos(S)"

% Display symstr as a formula without evaluating the operations by using displayFormula. S in symstr is replaced by its value.

displayFormula(symstr)

% To evaluate the strings S and symstr as symbolic expressions, use str2sym.

S = str2sym(S)
expr = str2sym(symstr)

% Substitute the variable S with its value by using subs. Evaluate the result in double precision using double.

double(subs(expr))

%
% Copyright 2019 The MathWorks, Inc.