


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Write a Pascal program which will sketch the graph of a function defined in the program.
INPUT: Your program should read an integer n from the terminal and draw the graph of the function
This series converges to the line y = (1/π) x , for 0 ≤ x < π. For example, for n = 3, the series takes the form
You should run your program twice, once with n = 10 and once with n = 20.
OUTPUT: The graph should have the positive y -axis displayed horizontally and the positive x - axis vertically (so that one gets the normal configuration by turning the printout 90 degrees counter-clockwise). Your printers use 10 chars/inch horizontally and 6 chars/inch vertically. Suppose we decide to represent 1 unit on the y -axis by 5 inches or 50 characters, or 1/50 units per character. Then 1 unit on the x -axis must also be 5 inches or 5·6 = 30 lines, or 1/30 units per line. Thus the y -axis should use 61 characters to display y values from 0.0 to 1.2, while the x - axis uses 100 lines to display x values from 0.0 to 3.333. (The x values for successive lines are 0, 1/30, 2/30, 3/30,... , 100/30.) The points of the graph itself should be marked with a "+" as shown below. Both axes should have scaling marks exactly as shown. (The graph shown is only the first portion of what you should produce.)
0 0.2 0.4 0.6 0.8 1.0 1. |---------|---------|---------|---------|---------|---------|---> Y 0.0-* |* |* |* | + | + 0.2- + | + | + | + | + | + 0.4- +
Notes:
Extras for experts:
n = 100
f[x_,n_] := Block[{sum = 0.0}, For[i = 0, i < n, i++, sum += (-1)^i (1/(i+1)) N[Sin[(i+1)x],10] ] ; (2/Pi)sum ]