How to make a square wave from sine wave. If sine is applied to sine repeatedly, it gradually gets shaped into a Square wave. I have used the Nesting function in Mathematica to apply sine to Itself. For example, *level-2 *nesting means that the plotted function will be Sin[Sin[x]], *level-3 * will be Sin[Sin[Sin[x]]]. For various levels of Nesting one can observe the gradual transition from sinusoidal to a square. My computer was able to do that till level 20,000. For any higher numbers, the kernel crashed. A faster multicore processor should be able to do it for much higher levels. But it is apparent that at Level-infinity it will be a perfect square wave. And unlike a perfect square-wave which is continuous but not differentiable at certain points, this function is continuous and differentiable everywhere.

The gradual transition has been shown below with the level of Nesting Indicated.

A comparison plot of all the above in one graph is done below which gives an idea about the transition.

It should be mentioned that the application of Sine repeatedly to itself decreases the amplitude to a very low value and hence all the plots have been normalized. An *unnormalized* function is plotted below. Please notice the amplitude, it is really very low.

Here is an animation. It might be a be a bit fast (and slightly Cheesy) but it will give a good idea of the transition.

#### Improved Animations

##### Nest from 1 to 100 (Step 1)

##### Nest from 1 to 1000 (Step 20)

##### Nest from 1 to 10000 (Step 50)

#### Reason why this happens:

Sin[x] is a non linear function which means that the rate of its variation is different for different values of x. Mathematica takes the given input as radian value unless specified. So for every level of nesting, the range of the input value becomes smaller and smaller and hence it slowly starts emerging as a square wave. Also since the function is asymmetric, the positive values and the negative values remain with their signs. When the same is tried with Cosine, the result will be a constant value between 0.7 and 0.8. It is understandable why this happens because, it converts all the negatives into positive in the very first nesting.

You can get the Pdf of the program and Images here – Sine Nest Program

This PDF will be better in one way that you can zoom in and see the closeup of the plots without losing their quality.(There will be no pixellation like for .jpg or .png)

Its gr8 that you came up with different idea? am still trying to figure out why it does so (sin to square) ?

The answer is in the last paragraph.

very fantastic to convert into square

Thank you Mr Mahendra.

Glad you liked it.