92 views (last 30 days)

What does this warning mean? And how can I solve the problem?

Walter Roberson
on 29 Oct 2017

Edited: Walter Roberson
on 29 Oct 2017

In versions before R2017b, the only way to convert a character vector expression into a symbolic expression was to use sym() on the character vector. For whatever reason, Mathworks has chosen to say that is Not Good, and has been warning for several releases that the ability to sym() an expression will be going away.

The expectation is that outside of that routine the user would have done

syms x y t

f = x^2+y^2*sin(t);

turev_s(f, t, [x y t], [1 2 30])

and that the code would be,

function turev_s(x, y, d, r)

n = length(symvar(f));

if n == 1

s = diff(f,y);

sade = simplify(s)

pretty(s)

if any(r)

sonuc = double(subs(f, d, r));

end

elseif n == 2

s = diff(f,y);

sade = simplify(s)

pretty(s)

if any(r)

sonuc = double(subs(f, d, r));

end

elseif n == 3

s = diff(f,y);

sade = simplify(s)

pretty(s)

if any(r)

sonuc = double(subs(f, d, r));

end

end

fprintf('Sonuc = %.4f\n',sonuc);

end

... which has an error if there are no symbolic variables or more than 3 symbolic variables, and does the same thing in each of the cases. It also has a bug for the case where the r are all 0. It could be rewritten as

function turev_s(x, y, d, r)

s = diff(f, y);

sade = simplify(s) %no semi-colon -- want it to display

pretty(s) %no semi-colon -- want it to display

if any(r)

sonuc = double(subs(f, d, r));

fprintf('Sonuc = %.4f\n',sonuc);

end

As of R2017b, Mathworks added str2sym() to convert character vectors to symbolic expressions. The expressions need to be in MATLAB syntax -- the sym() version expected the expressions to be in MuPAD syntax (which might be why they want to get rid of it.)

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/363947-warning-support-of-strings-that-are-not-valid-variable-names-or-define-a-number-will-be-removed-in#comment_498592

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/363947-warning-support-of-strings-that-are-not-valid-variable-names-or-define-a-number-will-be-removed-in#comment_498592

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/363947-warning-support-of-strings-that-are-not-valid-variable-names-or-define-a-number-will-be-removed-in#comment_498593

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/363947-warning-support-of-strings-that-are-not-valid-variable-names-or-define-a-number-will-be-removed-in#comment_498593

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/363947-warning-support-of-strings-that-are-not-valid-variable-names-or-define-a-number-will-be-removed-in#comment_498601

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/363947-warning-support-of-strings-that-are-not-valid-variable-names-or-define-a-number-will-be-removed-in#comment_498601

Sign in to comment.