Indexing array of symbolic variables dependent on time

조회 수: 17 (최근 30일)
Morten Nissov
Morten Nissov 2020년 7월 16일
댓글: Walter Roberson 2020년 7월 16일
I need to create variable number of symbolic variables and access each of them individually. It is necessary that they are time varying for purposes of calling diff.
So far I can see that a variable number can be created by
N = 5 % number of variables for example
syms x(t) [1,N]
But if one then tries to access the first element, x1(t), this results in
>> x(1)
ans =
[ x1(1), x2(1)]

답변 (1개)

Walter Roberson
Walter Roberson 2020년 7월 16일
you cannot do that with the symbolic toolbox. The () indexing is incompatible between symfun and arrays.
If you need an array of symfun then it must be cell array.
  댓글 수: 2
Morten Nissov
Morten Nissov 2020년 7월 16일
Is it possible to generate a cell array containing a variable number of symbolic variables? Equivalent to syms x [1,N] but with a cell array instead of array.
Walter Roberson
Walter Roberson 2020년 7월 16일
x = str2sym(compose("x" + (1:4) + "(t)"))
This will be an array of symbols that live at the MuPAD level, and can be operated like
dsolve(diff(x(1),t) == t^2)
but they will not act like symbolic functions. For example if you had done
syms y(t)
then you could use y(0) to represent y evaluated at 0, but you cannot use x(1)(0) and would instead need to use subs(x(1),t,0)

댓글을 달려면 로그인하십시오.

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by