Having problem to change the value of extra parameters at each time step passed in ODE45 Solver
조회 수: 4 (최근 30일)
이전 댓글 표시
Muhammad Mudassar
2020년 1월 12일
댓글: Muhammad Mudassar
2020년 1월 13일
Hello, I have a set of two diffrential equations having some constants i.e. A, B, C and D and i have passed these extra parametres successfully in ODE45 solver too. I'm getting my results as well.
As i'm solving these equations for specific time i.e. at t= 0, 1, 2,.......10.
Now what I want to do is that I want to change the values of A, B, C and D at each time i.e at t=0 I have some values of A,B,C and D and then at t=1 I need to use different values of these constants and so on.
Here's code and a picture of my two differential equations.
clc
clear all
close all
A=1;
B=-4;
C=-2;
D=3;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% d1 w1 d2 w2
[t,y] = ode45(@(t,y) aa(t,y,A,B,C,D),[0:1:10], [5 -3]);
plot(t,y(:,1),t,y(:,2))
xlabel('Time t');
ylabel('Solution y');
legend('y_1','y_2')
function dydt1 = aa(t,y,A,B,C,D)
dydt1 = zeros(2,1);
dydt1(1) = A.*y(1)+B.*y(2).*(2.*y(1));
dydt1(2) = C.*y(1)+D.*(2.*y(1));
end
댓글 수: 0
채택된 답변
Thiago Henrique Gomes Lobato
2020년 1월 12일
You can do it accurately only by doing partial integrations (make a loop in ode45 for the time steps) and changing the variable either between those partial steps or with an time dependence in your function. Take a look at this answer (and commentary) to see an example of it that works https://de.mathworks.com/matlabcentral/answers/487643-adding-a-piecewise-time-dependent-term-in-system-of-differential-equation#answer_398394?s_tid=prof_contriblnk
추가 답변 (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!