Dear Friends,
I would like to know the short cut for the if conditions on the picture attached.
Top one is what I want and the bottom one is the Matlab code.
I do not want to hard code it in Mathematica by using IF[ ];
Thank you.
Try Piecewise
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}]]