How to preserve 2-d initial conditions after passing it into ode45?

5 ビュー (過去 30 日間)
savitha muthanna
savitha muthanna 2021 年 4 月 19 日
コメント済み: savitha muthanna 2021 年 4 月 20 日
Hi,
I pass 2d initial conditions, but ode45 linearizes it and makes the matrix into a 1-d array. How do I ensure it is handled as a 2-d array?
I have the following:
--------------------------------------
N=60;
x(1:N, 1:2*N) = 0; x(20,20)=1;
options = odeset('RelTol',1e-7);
[t1 y] = ode45('fputest1', [0:L:t], x, options, N);
-----------------------------------------------------
x is a 60x120 matrix. When I step through the code in ode45, x is a 7200 x 1, 1-d array. How do I ensure x remains a 2-d matrix? Also what are the dimensions of y, when the solver has finished? Is it 2-d if x is an array? What is it in the case x is a 2-d matrix?

採用された回答

Walter Roberson
Walter Roberson 2021 年 4 月 19 日
When I step through the code in ode45, x is a 7200 x 1, 1-d array. How do I ensure x remains a 2-d matrix?
To do that, write your own version of ode45. The Mathworks version will always pass in the boundary conditions as a column vector.
Most people deal with the situation by simply reshape() the input almost immediately.
Also what are the dimensions of y, when the solver has finished?
y will be length(t1) by numel(x).
Your function is required to return a column vector that is numel(x) by 1, and integrated versions of that column will become rows of the output.
What is it in the case x is a 2-d matrix
Then y will be length(t1) by numel(x).
You can reshape y afterwards, such as
yperm = permute(reshape(y, length(t1), size(x,1), size(x,2)),[2 3 1]);
and now yperm(:,:,iteration) will be the 2D results at time t1(iteration)
  5 件のコメント
Walter Roberson
Walter Roberson 2021 年 4 月 20 日
for i = 1 : size(yperm,3)
surf(yperm(:,:,i), 'edgecolor', 'none');
pause(1);
end
or
volumeViewer(yperm)
savitha muthanna
savitha muthanna 2021 年 4 月 20 日
Thanks so very much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by