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!