added kettenbruchentwicklung (aufgabe 1, blatt 4) -- voll mit bugs -- ;)
authorhackbard <hackbard>
Thu, 12 Feb 2004 13:36:26 +0000 (13:36 +0000)
committerhackbard <hackbard>
Thu, 12 Feb 2004 13:36:26 +0000 (13:36 +0000)
Makefile
kettenbruchentwicklung.c [new file with mode: 0644]

index a806075..b368059 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ CFLAGS = -O3 -Wall
 LIBS = -L/usr/lib -lm
 
 API = g_plot.o
-OBJS = newton zentral homogen integral-1_2 integral-2_2 polynom_interpolation
+OBJS = newton zentral homogen integral-1_2 integral-2_2 polynom_interpolation kettenbruchentwicklung
 
 all: $(OBJS)
 
@@ -27,6 +27,9 @@ integral-2_2: $(API)
 polynom_interpolation: $(API)
        $(CC) $(CFLAGS) -o $@ $(API) $(LIBS) polynom_interpolation.c
 
+kettenbruchentwicklung: $(API)
+       $(CC) $(CFLAGS) -o $@ $(API) $(LIBS) kettenbruchentwicklung.c
+
 clean:
        rm $(API) $(OBJS)
 
diff --git a/kettenbruchentwicklung.c b/kettenbruchentwicklung.c
new file mode 100644 (file)
index 0000000..3ab3445
--- /dev/null
@@ -0,0 +1,55 @@
+#include <stdio.h>
+#include <math.h>
+#include "g_plot.h"
+
+#define INT .5
+#define GENAUIGKEIT .5
+#define GENAUIGKEIT_2 (GENAUIGKEIT*GENAUIGKEIT)
+#define PI M_PI
+
+int main(int argc,char **argv) {
+       double f_n=0,f_a=0;
+       double A,A_1,A_2;
+       double B,B_1,B_2;
+       double a=0;
+       int i;
+       double x;
+       int fd;
+
+       /* parse command line */
+       if(argc!=2) {
+               printf("usage:\n");
+               printf("%s plotfile\n",argv[0]);
+               return -1;
+       }
+
+       /* main init */
+       x=0;
+       fd=gp_init(argv[1]);
+       
+       /* x loop */
+       while(x<4*PI) {
+
+               /* init */
+               A_1=0; A_2=x; A=x;
+               B_1=1; B_2=0; B=1;
+               i=1;
+               f_n=0;
+               f_n=f_a+2.0*GENAUIGKEIT;
+               /* loop bis y genuaigkeit */
+               while(!(((f_n-f_a)*(f_n-f_a))<GENAUIGKEIT_2)){
+                       f_a=f_n;
+                       i++;
+                       a=(i>>1)*(i>>1)*x;
+                       A=i*A_1+a*A_2;
+                       B=i*B_1+a*B_2;
+                       f_n=A/B;
+               }
+               printf("debug: x=%f, y=%f bei N=%d (a=%f)\n",x,f_n,i,a);
+               gp_add_data(fd,&f_n,1,1,TYPE_DOUBLE);
+               x+=INT;
+       }
+       gp_close(fd);
+       return 1;
+}
+