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 visualización (últimos 30 días)
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.

Respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by