]> hackdaworld.org Git - physik/computational_physics.git/commitdiff
added homogen.c
authorhackbard <hackbard>
Fri, 24 Oct 2003 01:45:06 +0000 (01:45 +0000)
committerhackbard <hackbard>
Fri, 24 Oct 2003 01:45:06 +0000 (01:45 +0000)
.cvsignore
Makefile
homogen.c [new file with mode: 0644]

index 4d0978485318105a7c3a55eacb1578ab20288263..dc865065ec5cd08a8bfc98a1fd32b9b236a893c5 100644 (file)
@@ -2,3 +2,4 @@
 *.plot
 newton
 zentral
+homogen
index 4efb3bda26f6f98bd798ba16bcc6eab3c599dfeb..8ee2fa638692802d3c1c8defdf34e2495f197965 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
+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 (file)
index 0000000..74d4721
--- /dev/null
+++ b/homogen.c
@@ -0,0 +1,63 @@
+/*
+ * homogen.c - bewegung im homogenen feld f=g(0,-1)
+ *
+ * usage: ./homogen <x_0> <y_0> <vx_0> <vy_o> <steps> <g> <alpha>
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <stdlib.h>
+#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 <x_0> <y_0> <vx_0> <vy_0> <steps> <g> <alpha>\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;
+}