Hi Sheng,
As Hans mentioned, you can use Piecewise
to do this
s3[t_] := Piecewise[{{(A t)/4, 0 <= t < 2.5}, {(-A t + 5 A)/4, 2.5 <= t < 5}}]
Block[{A = 1}, Plot[s3[t], {t, 0, 6}]]
You can also use DownValues
, which is closer to the Matlab
code
s3a[t_ /; 0 <= t < 2.5] := (A t)/4
s3a[t_ /; 2.5 <= t < 5] := (-A t + 5 A)/4
s3a[___] := 0
Block[{A = 1}, Plot[s3a[t], {t, 0, 6}]]