randFromArray( [ "cos", "sin" ] ) { "cos": "cosine", "sin": "sine"}[FN] randRange( 1, 5 ) / 2 random() < 0.5 ? randRange( 1, 4 ) : 1 / randRange( 1, 4 ) 2 * PI * HSCALE 3.5 3.5 * PI * HSCALE 150 / VRANGE 250 / HRANGE VSCALE + "*" + FN + "(x/" + HSCALE + ")" HSCALE * PI / 4 0.5 2 1 4 2

f(x) is graphed below.

graphInit({ range: [ HRANGE, VRANGE ], scale: [ PIXHSCALE, PIXVSCALE ], axisArrows: "<->", gridStep: [ HSCALE * PI / 4, .5 ], tickStep: [ 2, 1 ], labelStep: [ 2, 2 ], unityLabels: true, xLabelFormat: piFraction }); // draw sin/cos curve style({ stroke: "#a3a3ff", strokeWidth: 2 }, function() { plot( function( x ) { return eval( FUNCS ); }, [ -HRANGE, HRANGE ] ); });

What is f(x)?

f(x)= VSCALE FN (1 / HSCALEx)

The function starts at its maximum value (ie, f(0)=VSCALE), so what kind of function is it?

The cosine function, \cos(x), starts at 1 (ie, \cos(0)=1), so f(x) must be a scaled version of the cosine function.

The function starts at zero (ie, f(0)=0), so what kind of function is it?

The sine function, \sin(x), starts at 0 (ie, \sin(0)=0), so f(x) must be a scaled version of the sine function.

style({ stroke: "#00d505", strokeWidth: 2 }, function() { plot( function( x ) { return eval( FUNCS ); }, [ 0, PERIOD ] ); line( [ 0, VSCALE ], [ PERIOD , VSCALE ], { arrows: "<->" }); });

The distance from peak to peak is piFraction( PERIOD ), so the period of f(x) is piFraction( PERIOD ).

The distance between every other zero is piFraction( PERIOD ), so the period of f(x) is piFraction( PERIOD ).

The period of a normal FNS function is 2\pi, and the period we want is piFraction( PERIOD ), so we don't need to worry about scaling the function horizontally.

The period of a normal FNS function is 2\pi, and the period we want is piFraction( PERIOD ), so we need to scale the FNS function horizontally by decFrac( PERIOD / 2 / PI ).

To horizontally scale \FN(x) by decFrac( PERIOD / 2 / PI ), we need to substitute decFrac( 2 * PI / PERIOD )x in for x to get \FN(decFrac( 2 * PI / PERIOD )x).

style({ stroke: "#00d505", strokeWidth: 2 }, function() { var x = FN === "sin" ? PERIOD / 4 : PERIOD; line( [ x, 0 ], [ x, VSCALE ], { arrows: "<->" }); });

The height of f(x) is decFrac( VSCALE ), so the amplitude of f(x) is decFrac( VSCALE ).

The amplitude of f(x) is 1, so we don't need to worry about scaling the function vertically.

The amplitude of f(x) is decFrac( VSCALE ), so we need to scale FNS function vertically by decFrac( VSCALE ).

To scale the function vertically, multiply the whole thing by decFrac( VSCALE ).

So the resulting function (after we perform all these manipulations) is plus( toFractionTex( VSCALE ) + "\\" + FN + "(" + plus( toFractionTex( 1 / HSCALE ) + "x" ) + ")" ).