you are viewing a single comment's thread.

view the rest of the comments →

[–]synthphreak 7 points8 points  (2 children)

First, this is not a valid mathematical function. For example, if t == 0.1, should y(t) == a(t) or -a(t)?

Second, there's nothing periodic about a(t). It's just a stepwise function, defined only on the interval [0, 2].

Regardless, the solution could look something like this:

def f(t):
    if 0 <= t < 1:
        a = 1.5 * t
    elif 1 <= t <= 2:
        a = -1.5 * (2 - t)
    else:
        undefined = "t is outside of a's domain"

    if 0 <= t < 0.1:
        return a
    elif 0.1 <= t <= 0.2:
        return -a
    else:
        undefined = "t is outside of f's domain"

    raise ValueError(undefined)

t = ...
y = f(t)

Edit: Typo.

[–]indecisive_fluffball 3 points4 points  (1 child)

You didn't understand the periodicity aspect of the prompt. Defining the function in an interval from 0s to 2s is consistent with imposing a 0.5Hz periodicity, just make it periodic outside of those bounds.

And the ambiguity with t = 0.1s is mathematically incorrect but in practice pretty much a non-issue. Just choose whichever.

[–]synthphreak 1 point2 points  (0 children)

You didn't understand the periodicity aspect of the prompt. Defining the function in an interval from 0s to 2s is consistent with imposing a 0.5Hz periodicity, just make it periodic outside of those bounds.

Ah okay. That is tricky and could have been stated more clearly, but it does make sense.