我有一个带有一些未知参数的微分方程系统,我需要找到最适合我拥有的数据的最佳参数集。
对于每个参数集选择(使用 for 循环),我的代码以数值方式求解 DE 系统,然后从时间向量中提取与数据时间值一致的时间子向量。下一步需要为每个与时间子向量匹配的变量提取一个新的输出子向量(以计算误差)。
这是我的代码的外观:
OO=[];
y2=(y(:,2))';
t1=t';
FF=[];
y1=(y(:,1))';
global "parameters and other global variables"
for parameter_1
for parameter_2
[t,y]=ode45('system',[time interval], [initial conditions]);
time; % "time" is a code that extracts the time subvector
for i=1:length(time)
for j=1:length(t1)
if time(i)==t1(j);
FF(end+1) = y1(j);
end
end
end
for k=1:length(time)
for m=1:length(t1)
if time(k)==t1(m);
OO(end+1) = y2(m);
end
end
end
end
end
此时代码还没有结束,但我希望它返回OO向量和FF用于循环的最后一个参数集选择的向量。但是,当代码运行(没有任何错误)时,它会产生向量OO并且FF比向量时间长:length(time) < {length(OO),length(FF)}.