フィルターのクリア

array of symbolic variables which are function of time

8 ビュー (過去 30 日間)
Jai Tushar
Jai Tushar 2017 年 10 月 25 日
編集済み: Juraj Lieskovský 2021 年 3 月 4 日
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),.... .

採用された回答

Walter Roberson
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
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.
Jai Tushar
Jai Tushar 2017 年 10 月 28 日
編集済み: Jai Tushar 2017 年 10 月 28 日
it worked!!
what does uniform and 0 do in the code?
Also,
ptemp = arrayfun(@(N) sym(sprintf('p%d(t)',N)), (1:2), 'uniform', 0); p = vertcat(ptemp{:});
A = [1 2; -1 1]; odes = diff(p) == A*p
Gives me the output as
odes =
diff(p1(t), t) == p1(t) + 2*p2(t)
diff(p2(t), t) == p2(t) - p1(t)
Why is odes not the funtion of time in the output. When i define p1(t),... and so on manually and define P = [p1; p2] then odes == diff(P) = A*p gives odes as a function of time i.e. odes(t) in the output. W

サインインしてコメントする。

その他の回答 (2 件)

Juraj Lieskovský
Juraj Lieskovský 2021 年 3 月 4 日
編集済み: Juraj Lieskovský 2021 年 3 月 4 日
Simple solution (using R2020b)
syms t
syms p(t) [m,1]

KSSV
KSSV 2017 年 10 月 26 日
syms p1(t) p2(t) p3(t)
p = [p1 p2 p3]
  1 件のコメント
Jai Tushar
Jai Tushar 2017 年 10 月 26 日
編集済み: Jai Tushar 2017 年 10 月 26 日
you are defining p1(t),... manually here.
I want my script to define them according to the size of the square matrix i enter. For example if i have a (user input) nxn matrix, then the script should define n such symbolic variables which are functions of time.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNumeric Solvers についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by