Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
27 lines (24 sloc) 576 Bytes
% func: Funktion
% a: Untere Grenze Intervall
% b: Obere Grenze Intervall
% n:
% Rf:
% Bsp aus Skript Aufgabe 6.6:
% SimpsonRegel(@(x)(1/x), 2, 4, 4)
% Bsp Serie 13 Aufg 6.9
% SimpsonRegel(@(x) exp(-x^2), 0, 0.5, 3)
function [Sf] = SimpsonRegel(func, a, b, n)
h = (b-a)/n;
sum1 = 0;
sum2 = 0;
for k=1:n-1
xk = a + k*h;
sum1 = sum1 + func(xk);
end
for k=1:n
xk_1 = a+(k-1)*h;
xk = a + k*h;
sum2 = sum2 + func((xk_1+xk)/2);
end
Sf = (h/3) * (0.5*func(a) + sum1 + 2*sum2 + 0.5*func(b));
end
You can’t perform that action at this time.