define generate # Usage: loop N generate; $1=Counter; $2=N; uses \9. set $1 $1 + 1 # Increment the counter. set \9 4 * pi * (((2 * \10) - $2) / ($2 - 1)) set x[$1] \9 # Set x[i] equal to 4*pi*(((2*i)-N)/(N-1)). set \9 abs(\9) # \9 now equals abs(x). set y[$1] cos(\9) / (1 + \9) # Set y[i] equal to cos(|x|) / (1 + |x|). end viewport 0.25 0.85 0.3 0.8 # Set the viewport scale. expand 1.2 # Set the character size. font 2 # Set the font type. set \10 0 # Initialize the counter. loop 100 generate \10 100 # Fill the x and y arrays. set \0 4 * pi # Save 4 * pi. limits -\0 \0 -0.5 1.2 # Set the limits as -4pi, 4pi, -0.5, 1.2. box bcnst bcnstv # Draw the box. connect # Draw the curve. symbol 2 # Select the `+' symbol. points # Draw the points. expand 1.5 # Set the character size a bit bigger. mtext T 1.0 0.5 0.5 y = cos(|x|) / (1 + |x|) expand 1.2 # Reset the character size. xlabel (x) ylabel (y)
Figure E.6: A plot with data generated internally.