# How to solve a system of differential equations that has a term expressed with interp1 function?

1 view (last 30 days)
Angelo Dumitriu on 2 Sep 2018
Commented: Angelo Dumitriu on 2 Sep 2018
Hello,
I have a system of differential equations in which the derivatives are performed with respect to time. In some equations I have a term (not unknown) that depends on time because it is, at the specified time, the interpolation of a given curve (set of points), that is a curve that varies with time. I tried to solve with ode113 writing the interp1 function in the system inside the function that ode113 needs to work, but it seems that Matlab can't perform this task because if I change the values of the curve at some interpolation points, the result doesn't change. Instead if I change the initial conditions, the result changes (I think it is because Matlab solves the system with constant values assigned to the function interp1 that it pickes from the initial conditions, but I need it to solve for the whole curve not only for the initial conditions). Is there a way to solve my system?

Walter Roberson on 2 Sep 2018
Edited: Walter Roberson on 2 Sep 2018
Any time you have a system like that, you have discontinuities in the derivative of the function, and that makes it unsuitable for the ode*() routines, as the ode*() routines require continuity of the first two derivatives of the function being calculated. (In some cases, the delay differential routines are suitable.)
To get around this, you need to stop the integration at each of the breakpoints in the interpolation, and then resume again where you left off with the new value of the term. You would do this by looping, along the lines of
y0 = initial conditions
break_times = [.... list of times]
for K = 1 : length(break_times)-1
tspan = [break_times(K), mean(break_times(K:K+1)), break_times(K+1)];
[tK, yK] = ode113(@yourfunction, tspan, y0);
if K > 1; tK = tK(2:end); yK = yK(2:end,:); end
t{K} = tK: y{K} = yK;
y0 = YK(end,:);
end
t = vertcat(t{:});
Y = vertcat(y{:});
##### 2 CommentsShow NoneHide None
Angelo Dumitriu on 2 Sep 2018
Looks cool. I'm going to try it.
Angelo Dumitriu on 2 Sep 2018
It works perfectly.

### Categories

Find more on Ordinary Differential Equations 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!