added random stuff
[physik/computational_physics.git] / kettenbruchentwicklung.c
1 #include <stdio.h>
2 #include <math.h>
3 #include "g_plot.h"
4
5 #define INT .5
6 #define GENAUIGKEIT .5
7 #define GENAUIGKEIT_2 (GENAUIGKEIT*GENAUIGKEIT)
8 #define PI M_PI
9
10 int main(int argc,char **argv) {
11         double f_n=0,f_a=0;
12         double A,A_1,A_2;
13         double B,B_1,B_2;
14         double a=0;
15         int i;
16         double x;
17         int fd;
18
19         /* parse command line */
20         if(argc!=2) {
21                 printf("usage:\n");
22                 printf("%s plotfile\n",argv[0]);
23                 return -1;
24         }
25
26         /* main init */
27         x=0;
28         fd=gp_init(argv[1]);
29         
30         /* x loop */
31         while(x<4*PI) {
32
33                 /* init */
34                 A_1=0; A_2=x; A=x;
35                 B_1=1; B_2=0; B=1;
36                 i=1;
37                 f_n=0;
38                 f_n=f_a+2.0*GENAUIGKEIT;
39                 /* loop bis y genuaigkeit */
40                 while(!(((f_n-f_a)*(f_n-f_a))<GENAUIGKEIT_2)){
41                         f_a=f_n;
42                         i++;
43                         a=(i>>1)*(i>>1)*x;
44                         A=i*A_1+a*A_2;
45                         B=i*B_1+a*B_2;
46                         f_n=A/B;
47                 }
48                 printf("debug: x=%f, y=%f bei N=%d (a=%f)\n",x,f_n,i,a);
49                 gp_add_data(fd,&f_n,1,1,TYPE_DOUBLE);
50                 x+=INT;
51         }
52         gp_close(fd);
53         return 1;
54 }
55