Integrate definite integral with system of differential equations
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi all,
I have a fairly complex system of differential equations, and a part of which depends on a criterion c that uses definite integral of to change the system of differential equations from to as shown below:
I should note at this point that in the change from f to g, and is solution is known to be both smooth and continuous (which solves a lot of problems obviously), and that an analytic expression of is not available (which is what creates my problem).
With that said, I am struggling to implement this in MATLAB using ode45 because I can't obtain a numeric value of from within the odefun as ode45 is progressing through the solution. Here's a test code to demonstrate the above problem:
clear ; clc
tspan = [0 1] ;
y0 = [0 0] ;
c = 0.3 ;
[t,y] = ode45(@(t, y) odefun(t, y, c), tspan, y0);
function dydt = odefun(t, y, c)
dydt(1,:) = 1./(1+t.^2) ; % h(t)
if int_ht <= c % integral of h(t): how do I get the value of `int_ht`?
dydt(2,:) = 2*y(1) ; % f(t)
else
dydt(2,:) = y(1)^2 ; % g(t)
end
end
Granted, the above may not demonstrate the favourable smoothness and continuity characteristics that my original complicated problem does, but it does demonstrate the basic problem that I am facing.
Thanks for your help in advance.
댓글 수: 0
채택된 답변
David Hill
2021년 1월 3일
편집: David Hill
2021년 1월 3일
Can you just do something like this?
function dydt = odefun(t, y, c)
dydt(1,:) = 1./(1+t.^2) ; % h(t)
h=@(x)1./(1+x.^2);
if integral(h,0,t) <= c % may have to change the 0 to whatever the lower band is in tspan
dydt(2,:) = 2*y(1) ; % f(t)
else
dydt(2,:) = y(1)^2 ; % g(t)
end
end
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!