f = @(t) ...
    (t > 1 & t < 2) .* (2 * (1 - 2*t + t.^2)) + ...
    (t > 2 & t < 4) .* (2 * (-3 + 2*t)) + ...
    (t > 4 & t < 5) .* (-2 * (-5 - 4*t + t.^2));

fplot(f, [1, 5], 'LineWidth', 2);
xlabel('t');
ylabel('f(t)');
title('Piecewise Function using fplot');
grid on;
