Hi 민석 김,
While defining the myode function, one can find the interpolated function first and then compute the first and second order derivatives. The following code snippet might be helpful:
ft = linspace(0,10,49); % w = f
f = zeros(1,49);
for idx = 1:49
if ft(idx)<5.2083
f(idx) = 10;
else
f(idx) = 8;
end
end
gt = linspace(0,10,49);
g = 5.*(1-exp(-5.*gt)); % g = τ (t)
tspan = [0 10];
y0 = [-pi/6 0];
[t,y] = ode45(@(t,y) myode(t,y,ft,f,gt,g), tspan, y0);
plot(t,y)
function dydt = myode(t,y,ft,f,gt,g)
dydt = zeros(2,1);
f = interp1(ft,f,t); % Interpolate the data set (ft,f) at time t
g = interp1(gt,g,t); % Interpolate the data set (gt,g) at time t
dydt(1) = y(2);
dydt(2) = -2.*y(2)- f.*sin(y(1)) + g;
end
Hope this helps!