String to Sym deprecated

1 次查看(过去 30 天)
Mikhael MYARA
Mikhael MYARA 2017-2-9
Dear all,
I have a huge code using strings to build sym expressions, and I would like to publish this code on the Matlab networ. Unfortunately, since an update, I experience problems. To simplify in a short example, I wrote the following and I wanted to know what's wrong with the simple code :
>> syms a;
>> b=sym('a+1')
I obtain the following 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)
-----
I see that people use simengine :
>> evalin(symengine,'a+1')
This works without warning. But for the following expression :
>> evalin(symengine,'[0,0;0,0]')
I obtain an error :
------
Error using symengine
Invalid input. ']' is expected.
Error in mupadengine/evalin (line 111)
res = mupadmex(statement,output_type{:});
-----
What's wrong ? What alternative may I use to continue using strings to build symbolic expressions ?
Regards,
Mike

回答(1 个)

Karan Gill
Karan Gill 2017-2-13
As the warning says, please don't use string input. Is this helpful?
syms a
b = sym(a+1)
If you store strings, then use "eval".
syms a
b = eval('a+1')
b =
a + 1
Could you provide more information on why you use strings to store symbolic expressions?
Thanks, Karan (Symbolic doc)
  1 个评论
Sanket Karnik
Sanket Karnik 2017-2-15
I understand that you want to know how to get rid of '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. ' warning. To add to the Karan's comment please refer to the documentation of the sym, at top of the documentation you can see the example of the similar warning and how to fix it. I hope this helps you in resolving the issue.
Regards,
Sanket

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by