Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
29 lines (24 sloc) 527 Bytes
% diff = @(t, yt) 0.1*yt + sin(2*t);
%
% a = 0;
% b = 6;
% h = 0.2;
% n = (b - a) / h;
% y0 = 0;
% Aufruf:
% Euler_Klassisch(diff, a, b, n, y0);
%
% Beispiel aus Serie 13 Aufgabe 7.2
% f(t, y(t)) = t^2 + 0.1 * y(t)
% [x, y] = Euler_Klassisch(@(t, yt) t^2 + 0.1 * yt, -1.5, 1.5, 5, 0)
function[x, y] = Euler_Klassisch(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
x(i+1) = x(i) + h;
y(i+1) = y(i) + h * f(x(i), y(i));
end
end
You can’t perform that action at this time.