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;...
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
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개)


Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기


Community Treasure Hunt

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

Start Hunting!

Translated by