-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSquare.java
More file actions
36 lines (31 loc) · 1.04 KB
/
Square.java
File metadata and controls
36 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author USMANULLAH KHAN
*/
public class Square {
public static void main(String[] args) {
// number of line segments to plot
int n = Integer.parseInt(args[0]);
// the function y = sin(4x) + sin(20x), sampled at n+1 points
// between x = 0 and x = pi
double[] x = new double[n+1];
double[] y = new double[n+1];
for (int i = 0; i <= n; i++) {
for(int t=0; t<=Math.PI*6;t++){
x[i] =Math.PI * i / n;
y[i] =SquareWave.squarewave(0.25, t);
}}
// rescale the coordinate system
//StdDraw.setXscale(0,Math.PI);
//StdDraw.setYscale(-2.0, +2.0);
// plot the approximation to the function
for (int i = 0; i < n; i++) {
StdDraw.line(x[i], y[i], x[i+1], y[i+1]);
}
}
}