clf;
plot (t, y, t, u*0.1);
hold on;
plot([0, 5], [0.95, 0.95], 'r--');
plot([0, 5], [1.05, 1.05], 'r--');

% y(2) が [0.95, 1.05] の間に入る時間を求める

n = size(t,1);
ts = 100;
for k=n:-1:1
  if (y(k,2) < 0.95) | (y(k,2) > 1.05)
    ts = t(k);
    break;
  end
end

plot([ts, ts], [-1, 1.5], 'r--');
fprintf('settling time = %f [sec]\n', ts);
legend('Reference', 'x', 'theta1', 'theta2', 'u');
