How can i use this vector in my ODE function?

11 views (last 30 days)
I have a vector of infusion rate values that i want to use in a differential equation. The infusion rates are given by this:
tspan = [0,60];
time_vals = 0:1:tspan(end);
SNP_infratevals = zeros(size(tspan));
for i = 1:length(time_vals)
if time_vals(i) > 0 && time_vals(i) <= 10
SNP_infratevals(i) = 30;
elseif time_vals(i) > 10 && time_vals(i) <= 20
SNP_infratevals(i) = 20;
elseif time_vals(i) > 20 && time_vals(i) <= 25
SNP_infratevals(i) = 6*(time_vals(i)-20)+20; % function
elseif time_vals(i) > 25 && time_vals(i) <= 35
SNP_infratevals(i) = 50;
elseif time_vals(i) > 35 && time_vals(i) <= 45
SNP_infratevals(i) = -4*(time_vals(i)-35)+50; % function
elseif time_vals(i) > 45 && time_vals(i) <= 50
SNP_infratevals(i) = 10;
elseif time_vals(i) > 50 && time_vals(i) <= tspan(end)
SNP_infratevals(i) = 25;
end
end
and i want to use it in my function : CVODE(t, y, SNP_infusion) as "u" in the line: dx2dt = 1/tau2 * (u-x2-(alpha*x3));
Do I need to interpolate maybe? If so how?

Answers (1)

Torsten
Torsten on 6 Dec 2023
Integrate from t=0 to t=10 and use u = 30.
Restart the ode solver with the solution at t = 10 and integrate from t=10 to t = 20 with u = 20.
Restart the ode solver with the solution at t = 20 and integrate from t=20 to t = 25 with u = 6*(t-20)+20.
...

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!