
| Current Path : /var/www/web-klick.de/dsh/50_dev2017/1310__algorithms/Julia/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/web-klick.de/dsh/50_dev2017/1310__algorithms/Julia/test.jl |
function RKF45{T<:Float64}(f, g, h, t0, tf, v0::T, w0::T)
# Initial values
t = t0
v5 = v4 = v = v0
w = w0
tolerance = 10^(-5.0)
# Create list for future plots
t_list = [t]
v_list = [v]
w_list = [w]
# Values for a, b and c (as on Butcher's tableau)
a = [ 0 0 0 0 0 0;
1/4 0 0 0 0 0;
3/32 9/32 0 0 0 0;
1932/2197 -7200/2197 7296/2197 0 0 0;
439/216 -8 3680/513 -845/4104 0 0;
-8/27 2 -3544/2565 1859/4104 -11/40 0]
b = [16/135 0 6656/12825 28561/56430 -9/50 2/55;
25/216 0 1408/2565 2197/4104 -1/5 0]
c = [0 1/4 3/8 12/13 1 1/2]
# Relative to y
k = Float64[0 0 0 0 0 0]
# Relative to z
l = Float64[0 0 0 0 0 0]
# Compute the next terms
for i in t0:h:tf
# Compute the next values of K and L
for j in 1:6
k[j] = f(t + c[j] * h, v + (a[j,:] * k')[1], w + (a[j,:] * l')[1])*h
l[j] = g(t + c[j] * h, v + (a[j,:] * k')[1], w + (a[j,:] * l')[1])*h
end
############################################################################
# Compute the next value of V #
# Here we implemented a tolerance test #
############################################################################
v4 = v + (b[2] * k')[1] #
v5 = v + (b[1] * k')[1] #
#
error = abs(v5 - v4) #
if error > tolerance #
#
h = 0.9 * h * ((tolerance/error) ^ (0.25)) #
#
for j in 1:6 #
k[j] = f(t + c[j] * h, v + (a[j] * k')[1], w + (a[j] * l')[1])*h #
l[j] = g(t + c[j] * h, v + (a[j] * k')[1], w + (a[j] * l')[1])*h #
end #
#
v5 = v + (b[1,:] * k')[1] #
end #
#
v = v5 #
############################################################################
# Compute T and W with the right values of H and L, obtained after the tolerance test
t += h
w += (b[1,:] * l')[1]
# Append new values to the lists
push!(t_list,t)
push!(v_list,v)
push!(w_list,w)
end
return t_list, v_list, w_list
end
function f(t, v, w)
return (v*(v-a)*(1-v) - w + I)/ε
end
function g(t, v, w)
return (v - p*w - b)
end
ε = 0.005
a = 0.5
b = 0.15
p = 1.0
I = 0.0
h = 0.005
# Initial and final values of time
t0 = 0.0
tf = 8