X-Git-Url: https://www.hackdaworld.org/gitweb/?p=physik%2Fcomputational_physics.git;a=blobdiff_plain;f=homogen.c;fp=homogen.c;h=74d4721e3f3d23d1170bec6e8e57e8fafc50de45;hp=0000000000000000000000000000000000000000;hb=53bf1c9b8fa24799a5bb284c6e93e877dac813d0;hpb=5df96c501847a0db33e17ab397aa180b538c7ad9 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; +}