How to use different predefined 3D matrix per time step in a function file containing a differential equation to be solved by ode 45

1 回表示 (過去 30 日間)
I would like to evaluate the differential equation in matrix form dvdt = -(A - B*(R^-1)*B'*S)'*v - Q*rd using ode45, where A,B,Q and R are time varying matrices, rd is a constant row vector and v is the variable to integrate. This equation is defined in a function file. On the other hand, the 3D matrix S = S(:,:,250) is obtained independently of time in the calling file. The problem is that in my equation function I need to use each one of the matrices S for every time step in ode45 (e.g. S(:,:,1) for time step 1, S(:,:,2) for time step 2, S(:,:,3) for time step 3, etc) I was wondering how can I perform this process. The function file is:
function dvdt = myfun(t,v,S)
A = A(t); B = B(t); R = R(t); Q = Q(t);
dvdt = -(A - B*inv(R)*B'*S)'*v - Q*rd;
end
and the calling file is simply:
S = S(:,:,250); % Defined previously in this file
[t,v] = ode45(@(f,v) myfun(t,v,S),f,v0);
Thanks in advance.

回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by