Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
26 lines (21 sloc) 617 Bytes
% Bespiel aus Serie 13 Aufgabe 7.3 [x, y] = Runge_Kutta_4(@(x, yx) yx, 0, 1, 10, 1)
% f = funktion
% a = anfangwerts integral
% b = endwert integral
% n = a - b / h
% y0 = anfangswertporblem
function [x, y] = Runge_Kutta_4(f, a, b, n, y0)
h = (b-a)/n;
x = zeros(n+1, 1);
y = zeros(n+1, 1);
y(1) = y0;
x(1) = a;
for i=1:n
k1 = f(x(i), y(i));
k2 = f(x(i) + h/2, y(i) + h/2 * k1);
k3 = f(x(i) + h/2, y(i) + h/2 * k2);
k4 = f(x(i) + h, y(i) + h * k3);
x(i+1) = x(i) + h;
y(i+1) = y(i) + h * (1/6) * (k1 + 2*k2 + 2*k3 + k4);
end
end
You can’t perform that action at this time.