MATLAB Answers

why does dimension of input variable change in ode45

1 ビュー (過去 30 日間)
Elysi Cochin
Elysi Cochin 2021 年 4 月 22 日
編集済み: Elysi Cochin 2021 年 4 月 23 日
i wanted to compute ode45 with the following input
ABCD = [3453151,3880795,334228,236989;3527618,3939199,341859,245399;...
3576729,3975798,346881,252868;3644620,4029699,353472,260243;...
3721884,4091729,361841,267082;3793075,4147822,369323,274675;...
3872519,4212611,377834,280793;3954858,4280204,386087,287261;...
4017588,4328416,392930,294910;4064143,4363557,397217,302017];
y0 = ABCD;
[t,y] = ode45(@(t,y) first_order(t,y), tspan, y0);
when i check the value of y in the function first_order its dimension is a column vector of 40x1
but i pass it as a matrix of 10x4
why does that happen
is there mistake in the ode45 line i have written
why does the dimension change

採用された回答

James Tursa
James Tursa 2021 年 4 月 22 日
編集済み: James Tursa 2021 年 4 月 22 日
The dimension changes to a column vector because that is the way ode45( ) operates. Your derivative function needs to be able to accept a column state vector y, which you may want to reshape back into a matrix prior to using it. It also needs to return a column vector. E.g.,
function dydt = first_order(t,y,N)
y = reshape(y,10,4); % reshape input as matrix
:
dydt = dydt(:); % reshape output as column vector
end
Btw, you are missing the N in your function handle. E.g.,
[t,y] = ode45(@(t,y) first_order(t,y), tspan, y0);
should be
[t,y] = ode45(@(t,y) first_order(t,y,N), tspan, y0);

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by