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 (최근 30일)
이전 댓글 표시
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
채택된 답변
Walter Roberson
2017년 5월 22일
(sym(4)/3)^(sym(5)/6)*x^(sym(2)/3)
댓글 수: 2
Walter Roberson
2017년 5월 23일
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)
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!