a) og b)
function result = trapes(a,b,N,f) result = 0; h = (b-a)/(N-1); for i = 0:N-1 r = f(h*i+a); s = f((i+1)*h+a); result = result + trapezArea(r,s,h); end end function A = trapezArea(r,s,h) A = (r+s)*h/2; end
a) og b)
function result = trapes(a,b,N,f) result = 0; h = (b-a)/(N-1); for i = 0:N-1 r = f(h*i+a); s = f((i+1)*h+a); result = result + trapezArea(r,s,h); end end function A = trapezArea(r,s,h) A = (r+s)*h/2; end