2
votes

Didn't really know how to explain this in the title, so I'll just explain with an example: I want to define

y[t_]= {Cos[n*t], Sin[n*t]}

for -Pi/2n ≤ t ≤ Pi/2n Is there a way to do this? I need to put this condition because I need to prove something that only happens when t is in that interval.

1

1 Answers

2
votes

You can use this syntax:

y[t_] := {Cos[n t], Sin[n t]} /; Abs[t] <= Pi/(2 n)

With this, y[t] stays unevaluated if the condition is not satisfied. This only works if n is known and a concrete value of t is plugged in, otherwise it always yields only y[t].

If you want to work with the function symbolically, or want n to stay generic, you may try your luck with

y[t_] := If[Abs[t] <= Pi/(2 n), {Cos[n t], Sin[n t]}]

This stays symbolic (using the If) for a generic n and t, and if they are known, it is simplified to the value if the condition is satisfied and to Null if not. This may be a problem as Null does not display in output.

There's also Piecewise with a single condition:

y[t_] := Piecewise[{{{Cos[n t], Sin[n t]}, Abs[t] <= Pi/(2 n)}}]

but it gives 0 if condition not satisfied. You can change the latter value to something more suitable, but you won't achieve an "unevaluated" result.

Your choice will depend on what you expect in what situations.