How to solve a differential equation with a time-varying term?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all,
I'm trying to solve the following differential equation: x' = (A-B*K)*x, where A, B, and K are matrices. A and B are constant, but K is composed of different values (each corresponding to a different value in time).
This is the ode45 call I have:
[T,X] = ode45(@(t,x) sysfun(T,x,A,B,K,T),T,[1;0]);
Where T is my time vector I previously defined.
This is the sysfun function I defined:
function dx = sysfun(t,x,A,B,K,T)
dx = (A-B*K)*x;
end
My question is, how can I vary K? I'd like to be able to index it, but I don't understand how to do that. I saw some similar questions/answers but they didn't really help. I did find the following example from here
k = find(t >= timeserie,1);
k = max(1,k-1);
a = A(k);
However when I tried applying this to my code by doing the following, I just kept getting that k was always = 1 (instead of getting k =1, then k = 2, then k =3, etc).
function dx = sysfun(t,x,A,B,K,T)
k = find(t>=T)
k = max(1,k-1);
Kk = K(k,:);
dx = (A-B*Kk)*x;
end
Any help would be greatly appreciated. Thanks!
2 commentaires
Sam Chak
le 22 Nov 2022
Hi @Julian
Do you have the time-varying functions of the elements
in the matrix K?
It looks like the matrix K depends on some kind of a schedule.
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!