# functionfinding

• Jun 28th 2012, 07:00 AM
Emilijo
functionfinding
How to find function that have values:
f(0)=0, f(1)=0, f(2)=0, f(3)=0,... for period T=1
f(0)=0, f(1)=1, f(2)=0, f(3)=1,... for period T=2
f(0)=0, f(1)=1, f(2)=1, f(3)=0, f(4)=1, f(5)=1, f(6)=0,... for period T=3
f(0)=0, f(1)=1, f(2)=1, f(3)=1, f(4)=0, f(5)=1, f(6)=1, f(7)=1, f(8)=0,... for T=4
f(0)=0, f(1)=1, f(2)=1,..., f(n-1)=1, f(n)=0, f(n+1)=1,...,f(2n)=0,f(2n+1)=1,... T=n

or shortly:
0000000000000 T=1
0101010101010 T=2
0110110110110 T=3
0111011101110 T=4
...

So, I need general function in two variables f(n,T)
The function must NOT have MOD, CEILING or FLOOR function.

Please, give me an example for T = 3 or T = 4.
Thanks
• Jun 28th 2012, 01:17 PM
mfb
Re: functionfinding
What about a combination $\displaystyle cos(\frac{2\pi n x}{T})$ (n=0...[T/2])?
Basically the result of a fourier transformation, using the symmetry to get rid of the sin expressions.

In the T=3 case:
2/3-2/3cos(2pi x/3) goes 0110110...

In the T=4 case:
cos(0) goes 1, 1, 1, 1, 1,...
cos(2pi x/4) goes 1, 0, -1, 0, 1, ...
cos(4pi x/4) goes 1, -1, 1, -1, 1, ...

This gives you three interesting equations, using a0 to a2 as coefficients:

a0+a1+a2=0 (for f(0)=0)
a0-a2=1 (for f(1)=1)
a0-a1+a2=1 (for f(2)=1)

This is solved by a=3/4, b=-1/2, c=-1/4

Task for you: Check that 3/4 cos(0) - 1/2 cos(pi x/2) - 1/4 cos(pi x) is a solution.
And perform a fourier transformation for the general formula.
• Jun 29th 2012, 02:11 AM
Emilijo
Re: functionfinding
Quote:

Originally Posted by mfb
What about a combination $\displaystyle cos(\frac{2\pi n x}{T})$ (n=0...[T/2])?
Basically the result of a fourier transformation, using the symmetry to get rid of the sin expressions.

In the T=3 case:
2/3-2/3cos(2pi x/3) goes 0110110...

In the T=4 case:
cos(0) goes 1, 1, 1, 1, 1,...
cos(2pi x/4) goes 1, 0, -1, 0, 1, ...
cos(4pi x/4) goes 1, -1, 1, -1, 1, ...

This gives you three interesting equations, using a0 to a2 as coefficients:

a0+a1+a2=0 (for f(0)=0)
a0-a2=1 (for f(1)=1)
a0-a1+a2=1 (for f(2)=1)

This is solved by a=3/4, b=-1/2, c=-1/4

Task for you: Check that 3/4 cos(0) - 1/2 cos(pi x/2) - 1/4 cos(pi x) is a solution.
And perform a fourier transformation for the general formula.

(Wait)
But, is there a general function where I just put n and T, and I get solutions (1 or 0),
without doing all these stuff for certain period?
The formula has to be very practical so I can just put T=100 or T=1000... and n for example 379 and I get the value of the function.
• Jun 29th 2012, 02:53 AM
emakarov
Re: functionfinding
I don't have a ready answer, but may I ask why you can't use MOD, CEILING or FLOOR? Can you use piecewise-defined functions?
• Jun 29th 2012, 04:07 AM
Emilijo
Re: functionfinding
Quote:

Originally Posted by emakarov
I don't have a ready answer, but may I ask why you can't use MOD, CEILING or FLOOR? Can you use piecewise-defined functions?

I canīt use piecewise-defined functions. The problem must be solved only by elementary functions including any method (as fourier series, anything),
but no piecewise. The reason is that function must be derivable. Piecewise are not.
• Jun 29th 2012, 04:12 AM
emakarov
Re: functionfinding
Quote:

Originally Posted by Emilijo
The reason is that function must be derivable. Piecewise are not.

You can easily construct a required piecewise differentiable function from parabolas and constants.
• Jun 29th 2012, 04:23 AM
Emilijo
Re: functionfinding
Quote:

Originally Posted by emakarov
You can easily construct a required piecewise differentiable function from parabolas and constants.

No, in some points the function will not be differentiable.
• Jun 29th 2012, 04:33 AM
emakarov
Re: functionfinding
What about the following function f(x) on [0, 1]?

$\displaystyle f(x)=\begin{cases}2x^2&0\le x\le1/2\\-2x^2+4x-1&1/2<x\le1\end{cases}$
• Jun 29th 2012, 04:37 AM
Emilijo
Re: functionfinding
Well, I must have general function so I can just put n and T, I need function in "one piece",
no in 2 or more parts.
• Jun 29th 2012, 04:49 AM
emakarov
Re: functionfinding
Using parabolas on the sides and a constant in the middle, you can easily write a general piecewise function. In addition, this function is going to be dramatically cheaper computationally than a combination of a 1000 sines.
• Jun 29th 2012, 04:50 AM
Emilijo
Re: functionfinding
yes, but I need a function in one piece.
• Jun 29th 2012, 05:16 AM
mfb
Re: functionfinding
Do you want a smooth function, which can be differentiated as many times as you want? Even this can be solved with piecewise-definitions:
$\displaystyle f(x)=1-\exp(\frac{-1}{1-x^2})$ for |x-nT|<1 with any integer n, f(x)=1 otherwise.

If you want cos-compositions, evaluate the fourier transformation. Which is your task, not mine.