Why doesn't matlabFunction properly vectorize the state of an ode system?

2 ビュー (過去 30 日間)
Matthias Prechtl
Matthias Prechtl 2020 年 9 月 16 日
コメント済み: Matthias Prechtl 2020 年 9 月 27 日
Hey all,
i have reduced my problem to this simple demo case, where i define some ode, reduce its order with odeToVectorField and convert it to a matlab function.
t = sym('t');
c = sym('c');
d = sym('d');
x = str2sym('x(t)');
V = odeToVectorField(diff(diff(x)) == c + d);
matlabFunction(V, 'vars', {t, 'Y', [c; d]})
Outputs:
@(t,Y,in3)[Y(2);in3(1,:)+in3(2,:)]
With the parameters, it correctly vectorizes the parameter access, e.g. in3(2,:) instead of in3(2).
How can i get matlabFunction to vectorize the state as well, e.g. Y(2,:) instead of Y(2)?
Desired output:
@(t,Y,in3)[Y(2,:);in3(1,:)+in3(2,:)]

回答 (1 件)

Divija Aleti
Divija Aleti 2020 年 9 月 25 日
The symbols 'c' and 'd' can either be scalars or vectors.The vectorization for 'in3' is done as 'in3(1,:)' and 'in3(2,:)' so that they access the entire first and second rows of the matrix '[c; d]' respectively. However, the function 'odeToVectorField' returns a symbolic vector. Hence, the output shows 'Y(2)' and not 'Y(2,:)'.
Have a look at the following link to understand the algorithm used and what the symbol 'Y' means. A few examples are given too.
  1 件のコメント
Matthias Prechtl
Matthias Prechtl 2020 年 9 月 27 日
The underlying algorithm is clear based on engineering classes, 'Y' represents the system as a set of differential equations reduced to first order.
What's not clear to me is what changes i have to take to vectorize the outcoming equations automatically for more efficient solving. I can't find any hints in the document you linked.
I can manually modify the output of matlabFunction, but for sake of clarity and flexibility in my implementation, i'd like to automate that part.

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

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by