【发布时间】:2016-01-06 06:42:18
【问题描述】:
我在函数文件system3 中保存了相当长的方程组。我需要这个系统中的一个参数随时间变化。我创建了第二个函数calculate_a1,它在我的 401 个时间点中的每个时间点生成参数 a1 的向量。
tResult = [];
xResult = [];
tStep = linspace(0,400,401);
y0 = [IC];
alpha = calculate_a1();
for index = 2:numel(tStep)
% Integrate:
a1 = alpha(1,index);
t = tStep(index-1:index);
sol = ode45(@system3,t,y0,a1)
% Collect the results:
tResult = cat(1, tResult, t);
xResult = cat(1, xResult, x);
% Final value of x is initial value for next step:
y0 = x(end, :);
end
直到sol 行,这工作正常,但我正在努力导出a1 和ode45,以便它可以用来解决system3。任何帮助将不胜感激。
【问题讨论】:
-
寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及 在问题本身中重现它所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。
-
您知道 RHS(在您的情况下是 system3)可以接受时间作为参数吗?为什么不能在 system3 函数内部实现时间依赖? se.mathworks.com/help/matlab/ref/ode45.html?refresh=true
-
“我需要这个系统中的一个参数来随时间改变。” – 如果它取决于自变量时间,那么根据定义,它不是参数。正如@LutzL 所提到的,您可以在积分函数中使用插值 - 请参阅this question/answer for an example。如果“参数”仅在几个关键时间点发生变化,那么您可以尝试分段整合每个部分——请参阅 here 或 here。
标签: matlab ode numerical-integration