added polynom_interpolation,fixes inintegral-*, updated Makefile and cvsignore file
authorhackbard <hackbard>
Tue, 2 Dec 2003 10:47:57 +0000 (10:47 +0000)
committerhackbard <hackbard>
Tue, 2 Dec 2003 10:47:57 +0000 (10:47 +0000)
.cvsignore
Makefile
integral-1_2.c
integral-2_2.c
polynom_interpolation.c [new file with mode: 0644]

index dc86506..9fddb52 100644 (file)
@@ -3,3 +3,6 @@
 newton
 zentral
 homogen
 newton
 zentral
 homogen
+integral-1_2
+integral-2_2
+polynom_interpolation
index 3ba14bb..a806075 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ CFLAGS = -O3 -Wall
 LIBS = -L/usr/lib -lm
 
 API = g_plot.o
 LIBS = -L/usr/lib -lm
 
 API = g_plot.o
-OBJS = newton zentral homogen
+OBJS = newton zentral homogen integral-1_2 integral-2_2 polynom_interpolation
 
 all: $(OBJS)
 
 
 all: $(OBJS)
 
@@ -24,6 +24,9 @@ integral-1_2: $(API)
 integral-2_2: $(API)
        $(CC) $(CFLAGS) -o $@ $(API) $(LIBS) integral-2_2.c
 
 integral-2_2: $(API)
        $(CC) $(CFLAGS) -o $@ $(API) $(LIBS) integral-2_2.c
 
+polynom_interpolation: $(API)
+       $(CC) $(CFLAGS) -o $@ $(API) $(LIBS) polynom_interpolation.c
+
 clean:
        rm $(API) $(OBJS)
 
 clean:
        rm $(API) $(OBJS)
 
index be9a749..c286121 100644 (file)
@@ -6,7 +6,7 @@ int main(int argc,char **argv) {
  double p_N;
  double p;
  int start;
  double p_N;
  double p;
  int start;
- int i,j;
+ int i;
 
  if(argc!=3) { 
   printf("usage: %s <start> <startwert>\n",argv[0]);
 
  if(argc!=3) { 
   printf("usage: %s <start> <startwert>\n",argv[0]);
index 2c8a317..472a6c1 100644 (file)
@@ -6,7 +6,7 @@ int main(int argc,char **argv) {
  double p_N;
  double p;
  int steps;
  double p_N;
  double p;
  int steps;
- int i,j;
+ int i;
 
  if(argc!=2) { 
   printf("usage: %s <steps>\n",argv[0]);
 
  if(argc!=2) { 
   printf("usage: %s <steps>\n",argv[0]);
diff --git a/polynom_interpolation.c b/polynom_interpolation.c
new file mode 100644 (file)
index 0000000..587faa9
--- /dev/null
@@ -0,0 +1,64 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "g_plot.h"
+#include <string.h>
+
+#define I_START 5
+#define I_END 20
+#define I_LENGTH (I_END - I_START)
+#define N_I 3
+
+int main(int argc,char **argv) {
+ double *buf,*buf_i;
+ int N;
+ double step,step_i;
+ double x,x_i,x_j,x_k,w;
+ int i,j,k,l;
+ char file[64];
+ int fd;
+
+ if(argc!=2) {
+  printf("usage: %s <N>\n",argv[0]);
+  return 1;
+ }
+
+ N=atoi(argv[1]);
+ step=(double)I_LENGTH/(N+1);
+
+ /* savefile init */
+ strcpy(file,"polynom_interpolation.plot");
+ fd=gp_init(file);
+
+ /* calculate fixpoints */
+ buf=(double *)malloc((N+2)*sizeof(double));
+ for(i=0;i<N+2;i++) {
+  x=I_START+i*step;
+  buf[i]=(sin(x)-x*cos(x))/(x*x*x*x);
+  /* manually, gp_api sux! */
+  dprintf(fd,"%f %f\n",x,buf[i]);
+ }
+
+ /* do interpolation */
+ step_i=step/(N_I+1);
+ buf_i=(double *)malloc((N+1)*N_I*sizeof(double));
+ for(i=0;i<(N+1);i++) {
+  for(l=1;l<N_I+1;l++) {
+   buf_i[i*(N_I+1)+l]=0;
+   x_i=I_START+i*step+l*step_i;
+   for(j=0;j<(N+2);j++) {
+    x_j=I_START+j*step;
+    w=1;
+    for(k=0;k<(N+2);k++) {
+     x_k=I_START+k*step;
+     if(j!=k) w=w*((x_i-x_k)/(x_j-x_k));
+    }
+    buf_i[i*(N_I+1)+l]+=w*buf[j];
+   }
+   dprintf(fd,"%f %f\n",x_i,buf_i[i*(N_I+1)+l]);
+  }
+ }
+     
+ return 1;
+}