How to preserve 2-d initial conditions after passing it into ode45?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
savitha muthanna
am 19 Apr. 2021
Kommentiert: savitha muthanna
am 20 Apr. 2021
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?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 19 Apr. 2021
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 Kommentare
Walter Roberson
am 20 Apr. 2021
for i = 1 : size(yperm,3)
surf(yperm(:,:,i), 'edgecolor', 'none');
pause(1);
end
or
volumeViewer(yperm)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!