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. "?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Leo Simon
am 22 Mai 2017
Kommentiert: Walter Roberson
am 23 Mai 2017
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?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 22 Mai 2017
(sym(4)/3)^(sym(5)/6)*x^(sym(2)/3)
2 Kommentare
Walter Roberson
am 23 Mai 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)
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!