With the mod-function you are running into problems with neagtive values. The Mathcad modulo mod(x,m) unfortunately gives the result in the interval ]-m; m[ with the same sign as x. So mod (-13, 5) yields -3 and not +2, as we need here. You can use "mod(mod(t,T) + T, T)" as a workaround and stay in [0; m[.
For more complicated functions I would in the first step define an auxiliary function piecewise in one period, e.g. 0 to 2T in your case.
There are a lot of methods which comes to mind, e.g.
- using if-statements (nested, for more complex functions)
- using Mathcads programming facilities (looks best, in my opinion)
- use of the Heaviside function
- using boolean expressions
As a second step I would make this auxiliary function periodic by
- using the floor function, or by
- using a recursive definition
Of course you could combine the two steps in one function.
See the newly attached worksheet - hope it helps.
Regard
WR