sym error in define functions

조회 수: 2 (최근 30일)
Rastgo Mhamad
Rastgo Mhamad 2021년 3월 4일
댓글: Walter Roberson 2021년 3월 4일
when i define function by sym , exmp:
f = sym('4*xˆ3+4*xˆ2-7*x+2');
it show me this
Error using sym>convertChar (line 1448)
Character vectors and strings in the first argument can only specify a variable or number. To
evaluate character vectors and strings representing symbolic expressions, use 'str2sym'.
Error in sym>tomupad (line 1214)
S = convertChar(x);
Error in sym (line 211)
S.s = tomupad(x);
what is the solution. thanks.....

채택된 답변

Steven Lord
Steven Lord 2021년 3월 4일
As the error message states, "To evaluate character vectors and strings representing symbolic expressions, use 'str2sym'."
So use str2sym. Alternately define x to be a symbolic variable then build the symbolic expression using it.
syms x
y = x.^2 + 2*x -3
y = 
  댓글 수: 2
Rastgo Mhamad
Rastgo Mhamad 2021년 3월 4일
thank you so much.
Walter Roberson
Walter Roberson 2021년 3월 4일
Using sym('4*xˆ3+4*xˆ2-7*x+2') was permitted before R2018a if I recall correctly (might have been R2018a that was the last release.)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by