Integrate definite integral with system of differential equations
3 次查看(过去 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 个)
另请参阅
类别
在 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!