반응형
사각파 푸리에 시리즈
python 버전은 : https://daewonyoon.tistory.com/258
조금 지져분한 콘솔버전
/* By 숙제도둑
*/
#include <math.h>
#define PI 3.1415927
/*
* 1
* F (t) = ------- sin ( (2n+1) t )
* n 2n + 1
*
*/
double f(int n, double t)
{
return sin((2*n+1)*t)/(2*n+1);
}
/*
*
* k
* X (t) = Sigma F (t)
* k n = 1 n
*
*/
double X(int k, double t)
{
int n;
double sum = 0.0;
for(n=0; n<=k; n++)
{
sum += f(n, t);
}
//printf("%f\t%f\n", t, sum);
return sum;
}
void draw_graph(double t1, double t2, int n)
{
int Y = 70;
int i, j;
const double dt = PI/50;
double t, y;
char c;
#if 1
t = t1;
while(t<= t2)
{
y = X(n, t);
j = (int)(40*y+0.5); // y axis scaling
if((t*4/PI) -(double)((int)(t*4/PI)) < 0.05)
c = '-';
else
c = ' ';
for(i=-Y; i<=Y; i++)
{
if(i == j)
printf("*");
else if(i == 0)
printf("|");
else
printf("%c", c);
}
printf("%03.2f\t %03.4f\t", t, y);
printf("\n");
t+=dt;
}
#endif
}
int main()
{
int k[4] = { 1, 5, 50, 100 };
int i, t;
for(i=0; i<4; i++)
{
printf("Results for k=%d\n", k[i]);
draw_graph(0, 3*PI, k[i]);
}
return 0;
}
/*
c:\prompt > gcc src.c -lm
c:\prompt > a.exe > data.txt
*/
Results for k=1
----------------------------------------------------------------------*----------------------------------------------------------------------0.00 0.0000
| * 0.06 0.1253
| * 0.13 0.2480
| * 0.19 0.3660
| * 0.25 0.4769
| * 0.31 0.5787
| * 0.38 0.6697
| * 0.44 0.7486
| * 0.50 0.8144
| * 0.57 0.8665
| * 0.63 0.9048
| * 0.69 0.9295
| * 0.75 0.9414
----------------------------------------------------------------------|-------------------------------------*--------------------------------0.82 0.9414
| * 0.88 0.9311
| * 0.94 0.9120
| * 1.01 0.8861
| * 1.07 0.8554
| * 1.13 0.8219
| * 1.19 0.7879
| * 1.26 0.7551
| * 1.32 0.7256
| * 1.38 0.7008
| * 1.45 0.6822
| * 1.51 0.6706
| * 1.57 0.6667
| * 1.63 0.6706
| * 1.70 0.6822
| * 1.76 0.7008
| * 1.82 0.7256
| * 1.88 0.7551
| * 1.95 0.7879
| * 2.01 0.8219
| * 2.07 0.8554
| * 2.14 0.8861
| * 2.20 0.9120
| * 2.26 0.9311
| * 2.32 0.9414
----------------------------------------------------------------------|-------------------------------------*--------------------------------2.39 0.9414
| * 2.45 0.9295
| * 2.51 0.9048
| * 2.58 0.8665
| * 2.64 0.8144
| * 2.70 0.7486
| * 2.76 0.6697
| * 2.83 0.5787
| * 2.89 0.4769
| * 2.95 0.3660
| * 3.02 0.2480
| * 3.08 0.1253
----------------------------------------------------------------------*----------------------------------------------------------------------3.14 -0.0000
* | 3.20 -0.1253
* | 3.27 -0.2480
* | 3.33 -0.3660
* | 3.39 -0.4769
* | 3.46 -0.5787
* | 3.52 -0.6697
* | 3.58 -0.7486
* | 3.64 -0.8144
* | 3.71 -0.8665
* | 3.77 -0.9048
* | 3.83 -0.9295
* | 3.90 -0.9414
---------------------------------*------------------------------------|----------------------------------------------------------------------3.96 -0.9414
* | 4.02 -0.9311
* | 4.08 -0.9120
* | 4.15 -0.8861
* | 4.21 -0.8554
* | 4.27 -0.8219
* | 4.34 -0.7879
* | 4.40 -0.7551
* | 4.46 -0.7256
* | 4.52 -0.7008
* | 4.59 -0.6822
* | 4.65 -0.6706
* | 4.71 -0.6667
* | 4.78 -0.6706
* | 4.84 -0.6822
* | 4.90 -0.7008
* | 4.96 -0.7256
* | 5.03 -0.7551
* | 5.09 -0.7879
* | 5.15 -0.8219
* | 5.22 -0.8554
* | 5.28 -0.8861
* | 5.34 -0.9120
* | 5.40 -0.9311
* | 5.47 -0.9414
---------------------------------*------------------------------------|----------------------------------------------------------------------5.53 -0.9414
* | 5.59 -0.9295
* | 5.65 -0.9048
* | 5.72 -0.8665
* | 5.78 -0.8144
* | 5.84 -0.7486
* | 5.91 -0.6697
* | 5.97 -0.5787
* | 6.03 -0.4769
* | 6.09 -0.3660
* | 6.16 -0.2480
* | 6.22 -0.1253
* 6.28 0.0000
| * 6.35 0.1253
| * 6.41 0.2480
| * 6.47 0.3660
| * 6.53 0.4769
| * 6.60 0.5787
| * 6.66 0.6697
| * 6.72 0.7486
| * 6.79 0.8144
| * 6.85 0.8665
| * 6.91 0.9048
| * 6.97 0.9295
| * 7.04 0.9414
----------------------------------------------------------------------|-------------------------------------*--------------------------------7.10 0.9414
| * 7.16 0.9311
| * 7.23 0.9120
| * 7.29 0.8861
| * 7.35 0.8554
| * 7.41 0.8219
| * 7.48 0.7878
| * 7.54 0.7551
| * 7.60 0.7256
| * 7.67 0.7008
| * 7.73 0.6822
| * 7.79 0.6706
| * 7.85 0.6667
| * 7.92 0.6706
| * 7.98 0.6822
| * 8.04 0.7008
| * 8.11 0.7256
| * 8.17 0.7551
| * 8.23 0.7879
| * 8.29 0.8219
| * 8.36 0.8554
| * 8.42 0.8861
| * 8.48 0.9120
| * 8.55 0.9311
| * 8.61 0.9414
----------------------------------------------------------------------|-------------------------------------*--------------------------------8.67 0.9414
| * 8.73 0.9295
| * 8.80 0.9048
| * 8.86 0.8665
| * 8.92 0.8144
| * 8.98 0.7486
| * 9.05 0.6697
| * 9.11 0.5787
| * 9.17 0.4769
| * 9.24 0.3660
| * 9.30 0.2480
| * 9.36 0.1253
* 9.42 -0.0000
Results for k=5
----------------------------------------------------------------------*----------------------------------------------------------------------0.00 0.0000
| * 0.06 0.3654
| * 0.13 0.6655
| * 0.19 0.8561
| * 0.25 0.9265
| * 0.31 0.9005
| * 0.38 0.8244
| * 0.44 0.7482
| * 0.50 0.7080
| * 0.57 0.7152
| * 0.63 0.7571
| * 0.69 0.8071
| * 0.75 0.8390
----------------------------------------------------------------------|---------------------------------*------------------------------------0.82 0.8392
| * 0.88 0.8113
| * 0.94 0.7725
| * 1.01 0.7439
| * 1.07 0.7393
| * 1.13 0.7595
| * 1.19 0.7923
| * 1.26 0.8199
| * 1.32 0.8279
| * 1.38 0.8127
| * 1.45 0.7832
| * 1.51 0.7553
| * 1.57 0.7440
| * 1.63 0.7553
| * 1.70 0.7832
| * 1.76 0.8127
| * 1.82 0.8279
| * 1.88 0.8199
| * 1.95 0.7923
| * 2.01 0.7595
| * 2.07 0.7393
| * 2.14 0.7439
| * 2.20 0.7725
| * 2.26 0.8113
| * 2.32 0.8392
----------------------------------------------------------------------|---------------------------------*------------------------------------2.39 0.8390
| * 2.45 0.8071
| * 2.51 0.7571
| * 2.58 0.7152
| * 2.64 0.7080
| * 2.70 0.7482
| * 2.76 0.8244
| * 2.83 0.9005
| * 2.89 0.9265
| * 2.95 0.8561
| * 3.02 0.6655
| * 3.08 0.3654
----------------------------------------------------------------------*----------------------------------------------------------------------3.14 -0.0000
* | 3.20 -0.3654
* | 3.27 -0.6655
* | 3.33 -0.8561
* | 3.39 -0.9265
* | 3.46 -0.9005
* | 3.52 -0.8244
* | 3.58 -0.7482
* | 3.64 -0.7080
* | 3.71 -0.7152
* | 3.77 -0.7571
* | 3.83 -0.8071
* | 3.90 -0.8390
-------------------------------------*--------------------------------|----------------------------------------------------------------------3.96 -0.8392
* | 4.02 -0.8113
* | 4.08 -0.7725
* | 4.15 -0.7439
* | 4.21 -0.7393
* | 4.27 -0.7595
* | 4.34 -0.7923
* | 4.40 -0.8199
* | 4.46 -0.8279
* | 4.52 -0.8127
* | 4.59 -0.7832
* | 4.65 -0.7553
* | 4.71 -0.7440
* | 4.78 -0.7553
* | 4.84 -0.7832
* | 4.90 -0.8127
* | 4.96 -0.8279
* | 5.03 -0.8199
* | 5.09 -0.7923
* | 5.15 -0.7595
* | 5.22 -0.7393
* | 5.28 -0.7439
* | 5.34 -0.7725
* | 5.40 -0.8113
* | 5.47 -0.8392
-------------------------------------*--------------------------------|----------------------------------------------------------------------5.53 -0.8390
* | 5.59 -0.8071
* | 5.65 -0.7571
* | 5.72 -0.7152
* | 5.78 -0.7080
* | 5.84 -0.7482
* | 5.91 -0.8244
* | 5.97 -0.9005
* | 6.03 -0.9265
* | 6.09 -0.8561
* | 6.16 -0.6655
* | 6.22 -0.3654
* 6.28 0.0000
| * 6.35 0.3654
| * 6.41 0.6655
| * 6.47 0.8561
| * 6.53 0.9265
| * 6.60 0.9005
| * 6.66 0.8244
| * 6.72 0.7482
| * 6.79 0.7080
| * 6.85 0.7152
| * 6.91 0.7571
| * 6.97 0.8071
| * 7.04 0.8390
----------------------------------------------------------------------|---------------------------------*------------------------------------7.10 0.8392
| * 7.16 0.8113
| * 7.23 0.7725
| * 7.29 0.7439
| * 7.35 0.7393
| * 7.41 0.7595
| * 7.48 0.7923
| * 7.54 0.8199
| * 7.60 0.8279
| * 7.67 0.8127
| * 7.73 0.7832
| * 7.79 0.7553
| * 7.85 0.7440
| * 7.92 0.7553
| * 7.98 0.7832
| * 8.04 0.8127
| * 8.11 0.8279
| * 8.17 0.8199
| * 8.23 0.7923
| * 8.29 0.7595
| * 8.36 0.7393
| * 8.42 0.7439
| * 8.48 0.7725
| * 8.55 0.8113
| * 8.61 0.8392
----------------------------------------------------------------------|---------------------------------*------------------------------------8.67 0.8390
| * 8.73 0.8071
| * 8.80 0.7571
| * 8.86 0.7152
| * 8.92 0.7080
| * 8.98 0.7482
| * 9.05 0.8244
| * 9.11 0.9005
| * 9.17 0.9265
| * 9.24 0.8561
| * 9.30 0.6655
| * 9.36 0.3654
* 9.42 -0.0000
Results for k=50
----------------------------------------------------------------------*----------------------------------------------------------------------0.00 0.0000
| * 0.06 0.7096
| * 0.13 0.7472
| * 0.19 0.7607
| * 0.25 0.7678
| * 0.31 0.7723
| * 0.38 0.7755
| * 0.44 0.7779
| * 0.50 0.7798
| * 0.57 0.7814
| * 0.63 0.7827
| * 0.69 0.7839
| * 0.75 0.7849
----------------------------------------------------------------------|------------------------------*---------------------------------------0.82 0.7858
| * 0.88 0.7865
| * 0.94 0.7872
| * 1.01 0.7878
| * 1.07 0.7884
| * 1.13 0.7888
| * 1.19 0.7892
| * 1.26 0.7896
| * 1.32 0.7898
| * 1.38 0.7900
| * 1.45 0.7902
| * 1.51 0.7903
| * 1.57 0.7903
| * 1.63 0.7903
| * 1.70 0.7902
| * 1.76 0.7900
| * 1.82 0.7898
| * 1.88 0.7896
| * 1.95 0.7892
| * 2.01 0.7888
| * 2.07 0.7884
| * 2.14 0.7878
| * 2.20 0.7872
| * 2.26 0.7865
| * 2.32 0.7858
----------------------------------------------------------------------|------------------------------*---------------------------------------2.39 0.7849
| * 2.45 0.7839
| * 2.51 0.7827
| * 2.58 0.7814
| * 2.64 0.7798
| * 2.70 0.7779
| * 2.76 0.7755
| * 2.83 0.7723
| * 2.89 0.7678
| * 2.95 0.7607
| * 3.02 0.7472
| * 3.08 0.7096
----------------------------------------------------------------------*----------------------------------------------------------------------3.14 -0.0000
* | 3.20 -0.7096
* | 3.27 -0.7472
* | 3.33 -0.7607
* | 3.39 -0.7678
* | 3.46 -0.7723
* | 3.52 -0.7755
* | 3.58 -0.7779
* | 3.64 -0.7798
* | 3.71 -0.7814
* | 3.77 -0.7827
* | 3.83 -0.7839
* | 3.90 -0.7849
----------------------------------------*-----------------------------|----------------------------------------------------------------------3.96 -0.7858
* | 4.02 -0.7865
* | 4.08 -0.7872
* | 4.15 -0.7878
* | 4.21 -0.7884
* | 4.27 -0.7888
* | 4.34 -0.7892
* | 4.40 -0.7896
* | 4.46 -0.7898
* | 4.52 -0.7900
* | 4.59 -0.7902
* | 4.65 -0.7903
* | 4.71 -0.7903
* | 4.78 -0.7903
* | 4.84 -0.7902
* | 4.90 -0.7900
* | 4.96 -0.7898
* | 5.03 -0.7896
* | 5.09 -0.7892
* | 5.15 -0.7888
* | 5.22 -0.7884
* | 5.28 -0.7878
* | 5.34 -0.7872
* | 5.40 -0.7865
* | 5.47 -0.7858
----------------------------------------*-----------------------------|----------------------------------------------------------------------5.53 -0.7849
* | 5.59 -0.7839
* | 5.65 -0.7827
* | 5.72 -0.7814
* | 5.78 -0.7798
* | 5.84 -0.7779
* | 5.91 -0.7755
* | 5.97 -0.7723
* | 6.03 -0.7678
* | 6.09 -0.7607
* | 6.16 -0.7472
* | 6.22 -0.7096
* 6.28 0.0000
| * 6.35 0.7096
| * 6.41 0.7472
| * 6.47 0.7607
| * 6.53 0.7678
| * 6.60 0.7723
| * 6.66 0.7755
| * 6.72 0.7779
| * 6.79 0.7798
| * 6.85 0.7814
| * 6.91 0.7827
| * 6.97 0.7839
| * 7.04 0.7849
----------------------------------------------------------------------|------------------------------*---------------------------------------7.10 0.7858
| * 7.16 0.7865
| * 7.23 0.7872
| * 7.29 0.7878
| * 7.35 0.7884
| * 7.41 0.7888
| * 7.48 0.7892
| * 7.54 0.7896
| * 7.60 0.7898
| * 7.67 0.7900
| * 7.73 0.7902
| * 7.79 0.7903
| * 7.85 0.7903
| * 7.92 0.7903
| * 7.98 0.7902
| * 8.04 0.7900
| * 8.11 0.7898
| * 8.17 0.7896
| * 8.23 0.7892
| * 8.29 0.7888
| * 8.36 0.7884
| * 8.42 0.7878
| * 8.48 0.7872
| * 8.55 0.7865
| * 8.61 0.7858
----------------------------------------------------------------------|------------------------------*---------------------------------------8.67 0.7849
| * 8.73 0.7839
| * 8.80 0.7827
| * 8.86 0.7814
| * 8.92 0.7798
| * 8.98 0.7779
| * 9.05 0.7755
| * 9.11 0.7723
| * 9.17 0.7678
| * 9.24 0.7607
| * 9.30 0.7472
| * 9.36 0.7096
* 9.42 -0.0000
Results for k=100
----------------------------------------------------------------------*----------------------------------------------------------------------0.00 0.0000
| * 0.06 0.7464
| * 0.13 0.7661
| * 0.19 0.7730
| * 0.25 0.7766
| * 0.31 0.7788
| * 0.38 0.7804
| * 0.44 0.7816
| * 0.50 0.7826
| * 0.57 0.7834
| * 0.63 0.7841
| * 0.69 0.7846
| * 0.75 0.7852
----------------------------------------------------------------------|------------------------------*---------------------------------------0.82 0.7856
| * 0.88 0.7860
| * 0.94 0.7863
| * 1.01 0.7866
| * 1.07 0.7869
| * 1.13 0.7871
| * 1.19 0.7873
| * 1.26 0.7875
| * 1.32 0.7876
| * 1.38 0.7877
| * 1.45 0.7878
| * 1.51 0.7879
| * 1.57 0.7879
| * 1.63 0.7879
| * 1.70 0.7878
| * 1.76 0.7877
| * 1.82 0.7876
| * 1.88 0.7875
| * 1.95 0.7873
| * 2.01 0.7871
| * 2.07 0.7869
| * 2.14 0.7866
| * 2.20 0.7863
| * 2.26 0.7860
| * 2.32 0.7856
----------------------------------------------------------------------|------------------------------*---------------------------------------2.39 0.7852
| * 2.45 0.7846
| * 2.51 0.7841
| * 2.58 0.7834
| * 2.64 0.7826
| * 2.70 0.7816
| * 2.76 0.7804
| * 2.83 0.7788
| * 2.89 0.7766
| * 2.95 0.7730
| * 3.02 0.7661
| * 3.08 0.7464
----------------------------------------------------------------------*----------------------------------------------------------------------3.14 -0.0000
* | 3.20 -0.7464
* | 3.27 -0.7661
* | 3.33 -0.7730
* | 3.39 -0.7766
* | 3.46 -0.7788
* | 3.52 -0.7804
* | 3.58 -0.7816
* | 3.64 -0.7826
* | 3.71 -0.7834
* | 3.77 -0.7841
* | 3.83 -0.7846
* | 3.90 -0.7852
----------------------------------------*-----------------------------|----------------------------------------------------------------------3.96 -0.7856
* | 4.02 -0.7860
* | 4.08 -0.7863
* | 4.15 -0.7866
* | 4.21 -0.7869
* | 4.27 -0.7871
* | 4.34 -0.7873
* | 4.40 -0.7875
* | 4.46 -0.7876
* | 4.52 -0.7877
* | 4.59 -0.7878
* | 4.65 -0.7879
* | 4.71 -0.7879
* | 4.78 -0.7879
* | 4.84 -0.7878
* | 4.90 -0.7877
* | 4.96 -0.7876
* | 5.03 -0.7875
* | 5.09 -0.7873
* | 5.15 -0.7871
* | 5.22 -0.7869
* | 5.28 -0.7866
* | 5.34 -0.7863
* | 5.40 -0.7860
* | 5.47 -0.7856
----------------------------------------*-----------------------------|----------------------------------------------------------------------5.53 -0.7852
* | 5.59 -0.7846
* | 5.65 -0.7841
* | 5.72 -0.7834
* | 5.78 -0.7826
* | 5.84 -0.7816
* | 5.91 -0.7804
* | 5.97 -0.7788
* | 6.03 -0.7766
* | 6.09 -0.7730
* | 6.16 -0.7661
* | 6.22 -0.7464
* 6.28 0.0000
| * 6.35 0.7464
| * 6.41 0.7661
| * 6.47 0.7730
| * 6.53 0.7766
| * 6.60 0.7788
| * 6.66 0.7804
| * 6.72 0.7816
| * 6.79 0.7826
| * 6.85 0.7834
| * 6.91 0.7841
| * 6.97 0.7846
| * 7.04 0.7852
----------------------------------------------------------------------|------------------------------*---------------------------------------7.10 0.7856
| * 7.16 0.7860
| * 7.23 0.7863
| * 7.29 0.7866
| * 7.35 0.7869
| * 7.41 0.7871
| * 7.48 0.7873
| * 7.54 0.7875
| * 7.60 0.7876
| * 7.67 0.7877
| * 7.73 0.7878
| * 7.79 0.7879
| * 7.85 0.7879
| * 7.92 0.7879
| * 7.98 0.7878
| * 8.04 0.7877
| * 8.11 0.7876
| * 8.17 0.7875
| * 8.23 0.7873
| * 8.29 0.7871
| * 8.36 0.7869
| * 8.42 0.7866
| * 8.48 0.7863
| * 8.55 0.7860
| * 8.61 0.7856
----------------------------------------------------------------------|------------------------------*---------------------------------------8.67 0.7852
| * 8.73 0.7846
| * 8.80 0.7841
| * 8.86 0.7834
| * 8.92 0.7826
| * 8.98 0.7816
| * 9.05 0.7804
| * 9.11 0.7788
| * 9.17 0.7766
| * 9.24 0.7730
| * 9.30 0.7661
| * 9.36 0.7464
* 9.42 -0.0000
728x90
'프로그래밍 > 숙제도둑질' 카테고리의 다른 글
[C#|초급] 사다리꼴 넓이 구하기 (0) | 2008.09.17 |
---|---|
[FORTRAN77|초급] exp 함수 테일러급수 (0) | 2008.05.10 |
[C|MFC|수치해석] 라그랑지 다항식 (0) | 2008.04.14 |
[Py|초급] 달팽이 이차원배열, 나머지연산과 논리연산 (0) | 2008.04.05 |
[C#|초급] 성적입력 및 출력 (0) | 2008.03.31 |