matlab使用sym出现警告提示

  matlab使用sym时出现:”警告: 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. “
在MATLAB中,sym函数用于创建符号数字、符号变量、符号对象。符号对象的类型是sym,可以通过class(S)来验证,这里S是一个符号对象。符号变量的优点是,使用符号变量运算得到的只是一个解析解,即sym将非符号对象(如,数字,表达式,变量等)A转换为符号对象,并存储在符号变量S中。。
  例如,在符号变量运算过程中pi就用pi表示,而不是具体的近似数值3.14或3.14159。使用符号变量进行运算能最大限度减少运算过程中因舍入造成的误差。符号变量也便于进行运算过程的演示。
  语法格式:
  S = sym(A)将非符号对象(如,数字,表达式,变量等)A转换为符号对象,并存储在符号变量S中。
但是在2017b版本后: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.)
意思是不支持无效变量名或定义数字的字符串转换,这将在将来的版本中删除。
较为通行的做法是,先定义符号变量,然后对符号表达式求解:
例如:

syms t;
f=sym(‘(2-exp(-2t))heaviside(t)’);
ezplot(f,[-1,10])

改为:

syms t;
f=sym((2-exp(-2t))heaviside(t));
ezplot(f,[-1,10])

或者去掉sym用法

文章目录