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

조회 수: 2 (최근 30일)
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)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by