why does dimension of input variable change in ode45

2 Ansichten (letzte 30 Tage)
Elysi Cochin
Elysi Cochin am 22 Apr. 2021
Bearbeitet: Elysi Cochin am 23 Apr. 2021
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

Akzeptierte Antwort

James Tursa
James Tursa am 22 Apr. 2021
Bearbeitet: James Tursa am 22 Apr. 2021
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);

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by