2016-03-28 91 views
0

我解微分方程系统用Matlab这样从MATLAB ODE求解如何比较结果

tspan = [0 10];  
res = ode15s(@(t,x) func,tspan,x0); 

,我有另外一个系统,它比@func指定的slighlty不同,解决像

res2 = ode15s(@(t,x) func2,tspan,x0); 

我想通过计算每个时间步的差异来比较结果。但由于Matlab解算器是可变时间步长,因此res.y(解)矩阵具有不同的列数。我如何使结果具有可比性?我试过

tspan = [0:0.01:10]; 

但是求解器似乎仍然使用可变的时间步长。那么我怎样才能使结果具有可比性?先谢谢你。

编辑:我想澄清,我不需要强制解算器采取任何具体步骤,只需要一种方法来插入结果或其他东西。换句话说,this不能帮助我。

回答

2

使用Matlab的内置的样条插值:

tFine = 0:0.01:10; 
resFine = interp1(res.x,res.y,tFine,'spline'); 
res2Fine = interp1(res2.x,res2.y,tFine,'spline'); 
1

如果速度不是问题,您可以使用tspan设置为[0 tf]多次解决每个等式,其中tf[0:0.01:10]的元素。这将保证解决方案的最后一个值是一个你需要的:

tsteps = [0:0.01:10] 
for tf in tsteps: 
    tspan = [0 tf]; 
    res = ode15s(@(t,x) func, tspan, x0); 
    res2 = ode15s(@(t,x) func2, tspan, x0); 
    % Extract whatever you need here 
end 
% Compare what you extracted here