You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

a) og b) og c)

 

function result = simpsons(a,b,N,f)
N = N+isEven(N)-1;
h = calcDelta(a,b,N);
result = h/3*f(h*0);
mult = [4,2];
for i = 1:N-1
    result = result +  h/3*f(h*i)*mult(mod(i,2)+1);
end
result = result + h/3*f(h*N);
end
function even = isEven(n)
even = mod(n,2)+1;
end

function h = calcDelta(a,b,n)
h = (b-a)/n;
end

 

 

  • No labels