I am solving a differential equation system with Matlab like this
tspan = [0 10];
res = ode15s(@(t,x) func,tspan,x0);
and I have another system that is slighlty different than the one specified in @func
, solved like
res2 = ode15s(@(t,x) func2,tspan,x0);
I would like to compare the results by calculating the difference at each time step. But since Matlab solvers are variable time step, the res.y (solutions) matrices have different number of columns. How can I make the results comparable? I tried
tspan = [0:0.01:10];
But the solvers still seem to use a variable time step. So how can I make the results comparable? Thank you in advance.
Edit: I wish to clarify, I do not need to force the solvers to take any specific steps, just need a method to interpolate the results or something. In other words, this does not help me.
Using Matlab's built-in spline interpolation:
tFine = 0:0.01:10;
resFine = interp1(res.x,res.y,tFine,'spline');
res2Fine = interp1(res2.x,res2.y,tFine,'spline');