class
pro{
public static void main(String args[]){
int s,sx,n;
double x,y;
double h;
double a[]=
new double
[101];
double b[]=new double[101];
int pulse[]=new int[101];
for (s=0;s<101;s++){
pulse[s]=0;
if (Math.random()>0.5)pulse[s]=1;
}
h=Math.PI/
100;
for (n=1;n<101;n++){
y=0;
for (s=-100;s<101;s++){
x=s*h;
sx=s;
if (sx<0)sx=-sx;
y=y+pulse[sx]*Math.cos(n*x)*h;
}
a[n]=y/Math.PI;
}
for (n=1;n<101;n++){
y=0;
for (s=-100;s<101;s++){
x=s*h;
sx=s;
if (sx<0)sx=-sx;
y=y+pulse[sx]*Math.sin(n*x)*h;
}
b[n]=y/Math.PI;
}
y=0;
for (s=-100;s<101;s++){
x=s*h;
sx=s;
if (sx<0)sx=-sx;
y=y+pulse[sx]*h;
}
a[0]=0.5*y/Math.PI;
for (s=-100;s<101;s++){
x=s*h;
sx=s;
if (sx<0)sx=-sx;
System.out.
print(pulse[sx]);
System.out.print(",");
System.out.println(fou(a,b,x));
}
}
public static double fou(double[] a,double[] b,double x){
double f1;
int n;
f1=a[0];
for (n=1;n<101;n++){
f1=f1+a[n]*Math.cos(n*x)+b[n]*Math.sin(n*x);
}
return f1;
}
}
最終更新:2010年09月27日 04:57