MATLAB: Time varying force with ode23

time varying force

Hi there
I have the following code:
tf = 1;
t = linspace(0,3);
Ft = zeros(length(t),1);
% Here I generate the force values at different time intervals.
for i = 1:length(t)
if t(i) <= tf
Ft(i) = Fo*sin(2*pi*t(i)/tf);
elseif t(i) > tf
Ft(i) = 0;
end
end
ic = [0, 0]; % Initial conditions
dXdt = @(t, x) [x(2);
Ft * 1/(m1+m2)];
[t, x] = ode23(dXdt, [0, 3], ic);
I'm struggling to incorportate this time varying force F(t) into the ode23 function.
Any help as to how I can maybe get this done?
Thanks in advance!

Best Answer

Use function handle
Ft = @(t) (t<=tf)*Fo*sin(2*pi*t/tf);
dXdt = @(t, x) [x(2);
Ft(t) * 1/(m1+m2)];