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!