From 8fc948825d4563572a1172aba6c0b998bc1d907c Mon Sep 17 00:00:00 2001 From: hackbard <hackbard> Date: Tue, 2 Dec 2003 10:47:57 +0000 Subject: [PATCH] added polynom_interpolation,fixes inintegral-*, updated Makefile and cvsignore file --- .cvsignore | 3 ++ Makefile | 5 +++- integral-1_2.c | 2 +- integral-2_2.c | 2 +- polynom_interpolation.c | 64 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 polynom_interpolation.c diff --git a/.cvsignore b/.cvsignore index dc86506..9fddb52 100644 --- a/.cvsignore +++ b/.cvsignore @@ -3,3 +3,6 @@ newton zentral homogen +integral-1_2 +integral-2_2 +polynom_interpolation diff --git a/Makefile b/Makefile index 3ba14bb..a806075 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ CFLAGS = -O3 -Wall 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) @@ -24,6 +24,9 @@ integral-1_2: $(API) 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) diff --git a/integral-1_2.c b/integral-1_2.c index be9a749..c286121 100644 --- a/integral-1_2.c +++ b/integral-1_2.c @@ -6,7 +6,7 @@ int main(int argc,char **argv) { double p_N; double p; int start; - int i,j; + int i; if(argc!=3) { printf("usage: %s <start> <startwert>\n",argv[0]); diff --git a/integral-2_2.c b/integral-2_2.c index 2c8a317..472a6c1 100644 --- a/integral-2_2.c +++ b/integral-2_2.c @@ -6,7 +6,7 @@ int main(int argc,char **argv) { double p_N; double p; int steps; - int i,j; + int i; if(argc!=2) { printf("usage: %s <steps>\n",argv[0]); diff --git a/polynom_interpolation.c b/polynom_interpolation.c new file mode 100644 index 0000000..587faa9 --- /dev/null +++ b/polynom_interpolation.c @@ -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; +} -- 2.39.5