MATLAB Answers

Why do I receive this error "Support of character vectors that are not valid variable names or define a number will be removed in a future release. "?

52 views (last 30 days)
I'm trying to differentiate an expression f which has a horrible coefficient, specifically, (4/3)^(5/6). I want to prevent matlab from giving me the answer to diff(f,x) in the form of an incomprehensible rational number. I can accomplish my objective as follows.
f = @(x) sym('(4/3)^(5/6)')*x^(2/3)
and then
simplify(diff(f,x))
returns
(4*2^(2/3)*3^(1/6))/(9*x^(1/3))
which is exactly what I want. However, it's accompanied by a stern warning:
Warning: Support of character vectors 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.
> In sym>convertExpression (line 1559)
In sym>convertChar (line 1464)
In sym>tomupad (line 1216)
In sym (line 179)
In @(x)sym('(4/3)^(5/6)')*x^(2/3)
In sym>funchandle2ref (line 1308)
In sym>tomupad (line 1206)
In sym (line 179)
In sym/privResolveArgs (line 921)
In sym/diff (line 21)
I can turn off the warning, but I don't want this functionality to go away, as threatened, in future releases. Is there a way to accomplish the same result without triggering the warning?

Accepted Answer

Walter Roberson
Walter Roberson on 22 May 2017
(sym(4)/3)^(sym(5)/6)*x^(sym(2)/3)
  2 Comments
Walter Roberson
Walter Roberson on 23 May 2017
Laziness. A rational value will be constructed as a symbolic rational if either the numerator or denominator or both are symbolic, so you only need to do one of the two. It is permissible to do both.
I tend to instead write something like
Q = @(v) sym(v, 'r');
Q(4/3)^Q(5/6)*x^Q(2/3)
Here, the 4/3 and 5/6 and 2/3 are constructed in double precision, and then the sym() operation approximates the double precision as a rational, reconstructing the fraction. It is a bit more computation work, but a bit less typing for me. But to avoid the potential for the reconstruction to not give back the same fraction, I would probably write
(Q(4)/3)^(Q(5)/6)*x^(Q(2)/3)

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!