array of symbolic variables which are function of time
조회 수: 9 (최근 30일)
이전 댓글 표시
p = sym('p', [m 1]);
the above code gives me an array of symbolic variables, where m is the size of the matrix. However i want to create an array of symbolic variables which are function of time i.e. p1(t),p2(t),.... .
댓글 수: 0
채택된 답변
Walter Roberson
2017년 10월 26일
There is no facility to do this. You will need to loop (or equivalent). For example in R2017b or later,
p = arrayfun(@(N) str2sym(sprintf('p%d(t)',N)), 1:5).'
댓글 수: 3
Walter Roberson
2017년 10월 26일
ptemp = arrayfun(@(N) sym(sprintf('p%d(t)',N)), (1:m).', 'uniform', 0);
p = vertcat(ptemp{:});
You might get m warnings along the line 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.
추가 답변 (2개)
Juraj Lieskovský
2021년 3월 4일
편집: Juraj Lieskovský
2021년 3월 4일
Simple solution (using R2020b)
syms t
syms p(t) [m,1]
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!