Shihui Guo

Matlab ODE function with changing arguments

The main point is to differentiate between arguments and parameters. Arguments can change during the ODE integration steps, but parameters cannot. See this simple example:


clear;
param = struct('beta', 1000);
[T,Y] = ode45(@(t, y)odeFun(t, y, param),[0 3],[2 0]);
function dy = odeFun(t, y, param)
if t > 1
	param.beta = 50;
end
dy = zeros(2,1);    % a column vector
dy(1) = y(2);
dy(2) = -param.beta*y(1);
点击查看评论