aded zentral.c
authorhackbard <hackbard>
Fri, 24 Oct 2003 00:45:27 +0000 (00:45 +0000)
committerhackbard <hackbard>
Fri, 24 Oct 2003 00:45:27 +0000 (00:45 +0000)
.cvsignore
Makefile
newton.c
zentral.c [new file with mode: 0644]

index 7c417c0..4d09784 100644 (file)
@@ -1,3 +1,4 @@
 *.o
-newton
 *.plot
+newton
+zentral
index c65ab86..4efb3bd 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,13 +5,16 @@ CFLAGS = -O3 -Wall
 LIBS = -L/usr/lib -lm
 
 API = g_plot.o
-OBJS = newton
+OBJS = newton zentral
 
 all: $(OBJS)
 
 newton: $(API)
        $(CC) $(CFLAGS) -o $@ $(API) $(LIBS) newton.c
 
+zentral: $(API)
+       $(CC) $(CFLAGS) -o $@ $(API) $(LIBS) zentral.c
+
 clean:
        rm $(API) $(OBJS)
 
index ee74b6e..068d892 100644 (file)
--- a/newton.c
+++ b/newton.c
@@ -18,7 +18,7 @@ int main(int argc,char **argv) {
  int i,j,steps;
  int fd; /* data file */
  double *buf;
- char filename[32];
+ char filename[64];
 
  if(argc!=5) {
   printf("usage: %s <steps> <alpha> <x_0> <v_0>\n",argv[0]);
diff --git a/zentral.c b/zentral.c
new file mode 100644 (file)
index 0000000..cf071cd
--- /dev/null
+++ b/zentral.c
@@ -0,0 +1,70 @@
+/*
+ * zentral.c - teilchen im zentralfeld
+ *
+ * usag: ./zentral <x_0> <y_0> <vx_0> <vy_0> <steps> <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_p,x,y_p,y,r_3; /* ortsvektor */
+ double vx_p,vx,vy_p,vy; /* geschwindigkeitsvektor */
+ int steps,i,j;
+ double tau;
+ double alpha,f_x,f_y;
+ int fd;
+ char filename[64];
+ double *buf;
+
+ if(argc!=7) {
+  printf("usage: %s <x_0> <y_0> <vx_0> <vy_0> <steps> <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]); alpha=atof(argv[6]);
+ tau=2*M_PI/steps;
+ sprintf(filename,"zentral_%f_%f_%f_%f_%d_%f.plot",x_p,y_p,vx_p,vy_p,steps,alpha);
+ fd=gp_init(filename);
+
+ /* allocate memory for data buffer */
+ if((buf=(double *)malloc(5*steps*sizeof(double)))==NULL) {
+  puts("malloc failed!");
+  return -1;
+ }
+ buf[0]=0;
+ buf[1]=x_p; buf[2]=y_p;
+ buf[3]=vx_p; buf[4]=vy_p;
+
+ /* loop */
+ for(i=0;i<steps;i++) {
+  r_3=x_p*x_p+y_p*y_p;
+  f_x=-alpha*x_p/r_3; f_y=-alpha*y_p/r_3;
+  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 */
+  j=5*i;
+  buf[5+j]=i*tau;
+  buf[6+j]=x; buf[7+j]=y;
+  buf[8+j]=vx; buf[9+j]=vy;
+  /* switch */
+  x_p=x; y_p=y;
+  vx_p=vx; vy_p=vy;
+ }
+
+ /* write to file */
+ gp_add_data(fd,buf,5,steps,TYPE_DOUBLE);
+ gp_close(fd);
+
+ free(buf);
+
+ return 1;
+}