I have rather lengthy system of equations saved in a function file, system3. I need one of the parameters in this system to change dependant on time. I have created a second function, calculate_a1, that produces a vector of the parameter a1 at each of my 401 time points.
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
Up until the sol line, this works fine, but I'm struggling to export a1 with ode45 so that it can be used to solve system3. Any help would be appreciated.