rendered paste body//C-versio
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char **argv) {
unsigned int i, n, steps = 16;
double phase, step = 1.0 / steps;
double fx[steps][2], Fu[steps][2], phases[steps];
int u, k = 1, N = steps;
double p;
for (i = 0, phase = 0.0; i < steps; ++i, phase += step)
{
fx[i][0] = 0.0;
fx[i][1] = 0.0;
fx[i][0] = sin(2.0*M_PI*phase);
phases[i] = phase;
}
for (u = 0; u < N; u++)
{
Fu[u][0] = 0.0;
Fu[u][1] = 0.0;
for (k = 0; k < N; k++) {
p = (2.0*M_PI*u*k)/N;
//printf("%.6f\n",p);
/* real */
Fu[u][0] += fx[k][0]*cos(p);
//printf("%.8f * %.8f\n", fx[k][0],cos(p));
printf("%.8f\n", (fx[k][0]*cos(p)));
/* imaginary */
Fu[u][1] += -fx[k][0]*sin(p);
}
printf("\n");
}
for (i = 0; i < steps; ++i)
printf ("%.4f\t%.8f\n", phases[i],fx[i][0]);
//for (i = 0; i < steps; ++i)
//printf ("%.8f\t%.8f\n", Fu[i][0],Fu[i][1]);
return EXIT_SUCCESS;
}
//Java-versio
public class Test {
public static void main(String[] args) {
int i, n, steps = 16;
double phase, step = 1.0 / steps;
double fx[][] = new double[steps][2];
double Fu[][] = new double[steps][2];
double phases[] = new double[steps];
int u, k = 1, N = steps;
double p;
for (i = 0, phase = 0.0; i < steps; ++i, phase += step)
{
fx[i][0] = 0.0;
fx[i][1] = 0.0;
fx[i][0] = Math.sin(2.0*Math.PI*phase);
phases[i] = phase;
}
for (u = 0; u < N; u++)
{
Fu[u][0] = 0.0;
Fu[u][1] = 0.0;
for (k = 0; k < N; k++) {
p = (2.0*Math.PI*u*k)/N;
//System.out.println((float)p);
/* real */
Fu[u][0] += fx[k][0]*Math.cos(p);
//System.out.println("%.8f * %.8f\n", fx[k][0],cos(p));
System.out.println((float)(fx[k][0]*Math.cos(p)));
/* imaginary */
Fu[u][1] += -fx[k][0]*Math.sin(p);
}
System.out.println();
}
for (i = 0; i < steps; ++i)
System.out.println(phases[i] + "\t" + (float)fx[i][0]);
//for (i = 0; i < steps; ++i)
//System.out.println( Fu[i][0]+ "\t" + Fu[i][1]);
}
}