How to solve a differential equation with a time-varying term?
조회 수: 17 (최근 30일)
이전 댓글 표시
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
Sam Chak
2022년 11월 22일
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.
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!