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 ; clctspan = [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)

endend

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.

## Best Answer