Integrate definite integral with system of differential equations

2 views (last 30 days)
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.

Accepted Answer

David Hill
David Hill on 3 Jan 2021
Edited: David Hill on 3 Jan 2021
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

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!