Warning: Support of strings that are not valid variable names or define a number will be removed in a future release. To create symbolic expressions, first create symbolic variables and then use operations on them.

13 次查看(过去 30 天)
What does this warning mean? And how can I solve the problem?
  3 个评论
Muhendisleksi
Muhendisleksi 2017-10-29
编辑:Walter Roberson 2017-10-29
for example:
turev_s('x^2+y^2*sin(t)','t','x,y,t',[1 2 30])
I get an alert when I make the above example. How can I solve this problem?
Can not I show the value of "s" as fprintf?
function turev_s(x, y, d, r)
f = sym(x);
n = length(symvar(f));
if n == 1
s = diff(f,y);
sade = simplify(s)
pretty(s)
if r ~= 0
sonuc = double(subs(f,{d},{r}));
end
elseif n == 2
s = diff(f,y);
sade = simplify(s)
pretty(s)
if r ~= 0
sonuc = double(subs(f,{d},{r}));
end
elseif n == 3
s = diff(f,y);
sade = simplify(s)
pretty(s)
if r ~= 0
sonuc = double(subs(f,{d},{r}));
end
end
fprintf('Sonuc = %.4f\n',sonuc);
end

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2017-10-29
编辑:Walter Roberson 2017-10-29
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.)

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by