How could one approximate a flat piecewise function using trigonometric identities?

179 Views Asked by At

I have a flat piecewise function that is a on the interval $-L<x<L$, and 0 outside of this boundary. Perhaps $a=1/(2L)$, or perhaps not. However, I am looking to approximate this with a continuous function, very preferably made of a combination (i.e. sum) of trigonometric identities. I have looked at other answers, but they either have a single step, rather than a rectangular interval, and don't seem to use trig identities to approximate this flat piecewise interval (where by flat, I mean constant over the interval). When I try to do this myself, I tend to get a quickly repeating function (i.e. not just one flat interval), and--more prominently--the interval isn't approximately flat. Could someone help me out, please?

My apologies for adding more constraints after the fact, but it turns out that this function should also be normalizable for what i'd be using it for.

And, in order to make this more feasible, this function should be within a larger interval $-a<x<a$, where $a>L$. For reference, I'm looking for an approximation of a rectangular shape (the piecewise constant function) inside of a larger, finite interval. Can someone help me out, please? Can such a function be reasonably constructed?

2

There are 2 best solutions below

2
On

Trig functions are periodic, so any approximation with trig functions will be periodic. Your function (considered as a function on the complete real line) is not periodic. On what interval are you trying to approximate this function? If you want to approximate this (non-periodic) function on the whole real line, trig functions won’t work. If you want to approximate it on some specific interval $I$ larger than $(-L,L)$, you can use trig functions (Fourier Series), which will approximate your function’s periodic extension from $I$ to the whole real line.

7
On

Perhaps this the kind of solution the OP is looking for. As required, we choose a function that is zero outside of the interval $(-L, L)$. Inside we choose a flat function, i.e. a constant $C$, in the smaller interval $(-K,K)$. We then connect the three regions by means of cosine functions.

$x \le -L$: $$f(x) = 0$$ $-L \le x \le -K$: $$f(x) = (C/2) * [1 - cos(\frac {\pi (L+x)} {L-K}) ]$$ $-K \le x \le K$: $$f(x) = C$$ $K \le x \le L$: $$f(x) = (C/2)*[1 - cos(\frac {\pi (L-x)} {L-K}]$$ $L \le x$: $$f(x) = 0$$

This is a piece-wise continous representation, as requested. The function and its first derivative are continuous. Note that one can choose the central region to be broad, by setting e.g. $K = 0.95 L$. Then the two transition regions are narrow. Or the flat region can be small or absent ($K = 0$).