From: hackbard Date: Fri, 24 Oct 2003 01:45:06 +0000 (+0000) Subject: added homogen.c X-Git-Url: https://hackdaworld.org/gitweb/?p=physik%2Fcomputational_physics.git;a=commitdiff_plain;h=53bf1c9b8fa24799a5bb284c6e93e877dac813d0 added homogen.c --- diff --git a/.cvsignore b/.cvsignore index 4d09784..dc86506 100644 --- a/.cvsignore +++ b/.cvsignore @@ -2,3 +2,4 @@ *.plot newton zentral +homogen diff --git a/Makefile b/Makefile index 4efb3bd..8ee2fa6 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ CFLAGS = -O3 -Wall LIBS = -L/usr/lib -lm API = g_plot.o -OBJS = newton zentral +OBJS = newton zentral homogen all: $(OBJS) @@ -15,6 +15,9 @@ newton: $(API) zentral: $(API) $(CC) $(CFLAGS) -o $@ $(API) $(LIBS) zentral.c +homogen: $(API) + $(CC) $(CFLAGS) -o $@ $(API) $(LIBS) homogen.c + clean: rm $(API) $(OBJS) diff --git a/homogen.c b/homogen.c new file mode 100644 index 0000000..74d4721 --- /dev/null +++ b/homogen.c @@ -0,0 +1,63 @@ +/* + * homogen.c - bewegung im homogenen feld f=g(0,-1) + * + * usage: ./homogen + * + */ + +#include +#include +#include +#include +#include "g_plot.h" + +int main(int argc,char **argv) { + double x,x_p,y,y_p,vx,vx_p,vy,vy_p; + double g,alpha,f_x,f_y,tau; + int i,steps; + int fd; /* data file */ + double buf[5]; + char filename[64]; + + if(argc!=8) { + printf("usage: %s \n",argv[0]); + return -1; + } + + /* init + starting conditions */ + x_p=atof(argv[1]); y_p=atof(argv[2]); + vx_p=atof(argv[3]); vy_p=atof(argv[4]); + steps=atoi(argv[5]); g=atof(argv[6]); alpha=atof(argv[7]); + tau=2*M_PI/steps; + sprintf(filename,"homogen_%f_%f_%f_%f_%d_%f_%f.plot",x_p,y_p,vx_p,vy_p,steps,g,alpha); + fd=gp_init(filename); + + buf[0]=0; + buf[1]=x_p; buf[2]=y_p; + buf[3]=vx_p; buf[4]=vy_p; + gp_add_data(fd,buf,5,1,TYPE_DOUBLE); + + /* loop */ + for(i=0;;i++) { + f_x=-alpha*vx_p; f_y=-g-alpha*vy_p; + x=x_p+vx_p*tau; y=y_p+vy_p*tau; + vx=vx_p+f_x*tau; vy=vy_p+f_y*tau; + /* save data */ + buf[0]=i*tau; + buf[1]=x; buf[2]=y; + buf[3]=vx; buf[4]=vy; + gp_add_data(fd,buf,5,1,TYPE_DOUBLE); + /* switch */ + x_p=x; y_p=y; + vx_p=vx; vy_p=vy; + /* stop at y~0 ! */ + if((y<=0)&&(i!=0)) break; + } + + printf("reached ground at step %d\n",i); + + /* close file */ + gp_close(fd); + + return 1; +}