From aecbba2bcfeb44a5cc89fe5d50666792538948b8 Mon Sep 17 00:00:00 2001 From: Valentin Gehrke Date: Sat, 23 May 2015 23:44:26 +0200 Subject: [PATCH] Verfahren von Heun --- heun.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 heun.py diff --git a/heun.py b/heun.py new file mode 100644 index 0000000..262dd60 --- /dev/null +++ b/heun.py @@ -0,0 +1,22 @@ +# Verfahren von Heun zur numerischen Lösung von Anfangswertaufgaben. + +def heun(xk,yk,h,ys): + xk1 = xk + h + yk1p = yk + h * ys(xk,yk) + yk1 = 0.5*(yk+yk1p+h*ys(xk1,yk1p)) + return (xk1,yk1p) + +def run_heun(K,h,x0,y0,ys): + if not isinstance(ys,list): ys = [ys] + if not isinstance(y0,list): y0 = [y0] + xk = x0 + yk = y0 + xks = x0 + yks = [ [v] for v in y0 ] + + for i in range(K): + for j in range(len(ys)): + xk,yk[j] = heun(xk,yk[j],h,ys[i]) + xks.append(xk) + yks[j].append(yk[j]) +