MATLAB: Getting wrong integration results

numerical integration

Hi,
I have some problems getting the right results for an ODE with ode113. The right hand side has some sparse events. I startet with
[t, y] = ode113(@qd, [0 10], [0 0]);
but even with the version below I get a wrong answer. The integrator is not seeing all the events. Or what am I doing wrong.
Thank you,
Thomas
function go
global A B
A = 2;
B= 0.4;
t=linspace(0,10,1000);
x = t;
for i=1:1000
x(i) = f(t(i));
end
plot(t,x)
axis([0 10 0 10])
pause
[t, y] = ode113(@qd, 0:0.01:10, [0 0]);
plot(t,y(:,2),'-')
grid on
function qd=qd(t,q)
qd=[q(2);f(t)];
function f = f(t)
global A B
t = t-floor(t);
f = 0;
if t<B/2
f = A-A/(B/2)*t;
end
if t>1-B/2
f = (t-(1-B/2))*A/(B/2);
end

Best Answer

MaxStep.