How to solve two differential equations simultaneously with one having a matrix form of initial condition?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Adham Alkhaja
el 17 de Abr. de 2020
Comentada: Adham Alkhaja
el 17 de Abr. de 2020
I have a set of two differential equations with initial conditions and was wondering how am I able to solve them simulateously using ODE 45? The equations are as shown below,


with initial conditions,


where
is the Jacobian matrix. I want to integerate these equations simulationeously (42 ODEs). How is it possible since one initial condition is in a vector form and the other is a matrix.
0 comentarios
Respuesta aceptada
Peter O
el 17 de Abr. de 2020
Hi Adham,
Just to be clear, it's an ordinary differential equation,
is
/
? If so, and each matrix term is separable, then you can just reorder them into a vector for the integration.
So if the below is an accurate representation of your problem:
phi = [x1, x2;
x3, x4]
phi_prime = [dx1/dt, dx2/dt
dx3/dt, dx4/dt]
Then
function dx = myDeriv(t,x)
actual_x = x(1);
actual_x_prime = f(actual_x, t);
phi_vector = x(2:end);
phi_matrix = reshape(phi_vector,6,7) % Assuming 6R x 7C here...
A = getA(t);
dphidt_matrix = A*phi_matrix; %
dphidt_vector = dphidt_matrix(:); % Reshape to column. MATLAB is column major ordering.
dx = [actual_x_prime;
dphidt_vector];
end
function A = getA(t)
% do whatever
end
And calling it:
phi0 = eye(6);
x0 = [actual_x0; phi0(:)];
tspan = [0 10];
[t,x] = ode45(@myDeriv,tspan, x0)
Finally reshape out your variables for each time point, because x will by n_t by 43 instead of the scalar vs time and matrix vs time variables you want:
actual_x_integrated = x(:,1);
phi_integrated = nan(6,7,length(t));
for ix =1:length(t)
phi_integrated(:,:,ix) = reshape(x(ix,2:end),6,7);
end
I believe that should do what you're after.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!