From: hackbard Date: Thu, 24 Jun 2004 12:03:32 +0000 (+0000) Subject: added runge kutta example X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;p=physik%2Fcomputational_physics.git added runge kutta example --- diff --git a/Makefile b/Makefile index 0af4236..e08fef7 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,12 @@ # computational physics Makefile, rules for all example programs +CC=gcc INCLUDEDIR = /usr/include CFLAGS = -O3 -Wall LIBS = -L/usr/lib -lm API = g_plot.o general.o -OBJS = newton zentral homogen integral-1_2 integral-2_2 polynom_interpolation kettenbruchentwicklung bessel_1 bessel_2 check_rand mc_int +OBJS = newton zentral homogen integral-1_2 integral-2_2 polynom_interpolation kettenbruchentwicklung bessel_1 bessel_2 check_rand mc_int nullstellen rk all: $(OBJS) @@ -42,7 +43,13 @@ check_rand: $(API) mc_int: $(API) $(CC) $(CFLAGS) -o $@ $(API) $(LIBS) mc_int.c +nullstellen: $(API) + $(CC) $(CFLAGS) -o $@ $(API) $(LIBS) nullstellen.c + +rk: $(API) + $(CC) $(CFLAGS) -o $@ $(API) $(LIBS) rk.c + clean: - rm $(API) $(OBJS) + rm -f $(API) $(OBJS) remake: clean all diff --git a/rk.c b/rk.c new file mode 100644 index 0000000..6572328 --- /dev/null +++ b/rk.c @@ -0,0 +1,59 @@ +#define _GNU_SOURCE +#include +#include + +#define N 10000 +#define M 100 +#define INT (2*M_PI) + + +double k[4][2]; +double y[N+1][2]; +double tau; +int i; + +double f0(double t,double y0,double y1) { + return y1; +} + +double f1(double t,double y0,double y1) { + double q=.5,b=1.15,w=1.0*2/3; + + return (-1.0*sin(y0)+b*cos(w*t)-q*y1); + // return -y0; +} + +int main() { + + y[0][0]=0; + y[0][1]=2; + + tau=INT/M; + + for(i=0;i