Generation of symbolic vector of functions
1 次查看(过去 30 天)
显示 更早的评论
I need to define a lot of symbolic variables for DAE solver.
Instead of using
sym f1(t) f2(t) % up to arbitrary fN(t)
i would prefer something like this
sym('f_%d(t)',[1 N])
or similar. But it seems that use of parenthes is not allowed. Is possible to generate programatically such vectors?
3 个评论
Walter Roberson
2021-1-26
John is not correct, it can be done and I have done it.
The case with [] without () is handled by calling sym() to generate the names and then processing the returned list of names. That does not work with () because sym() does not handle (). Handling of () is done by syms() calling symfun() to create the appropriate objects.
There is no reason why syms could not be reprogrammed to handle arrays of functions: it just has not been done.
采纳的回答
Walter Roberson
2021-1-26
syms("f_" + (1:N) + "(t)")
The output cannot be assigned to anything.
syms() must be used for this, not sym()
str2sym() will not work for this purpose, and instead will effectively give you back variable names that just happen to include '(' 't' ')' characters but which are not functions.
There is an alternative involving aarrayfun of a symfun call and 'uniform', 0
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!