simpsons 1/3 rule calculating error
이전 댓글 표시
i have this code that calculates the integral, but i am having trouble implementing the code part where i evaluate the error and make a graph between the error and the number of segments
function I = simp13(func,x0,xn,n,varargin)
if nargin < 3, error('São necessários pelo menos 3 argumentos de entrada');end
if ~(xn>x0), error('O limite superior deve ser maior que o limite inferior'); end
if nargin < 4 || isempty(n), n = 100; end
x = 0;
h = (xn-x0)/n;
s = func(x0,varargin{:});
for i = 1:(n-1)
x = x+h;
if mod(i,2) == 1
s = s + 4*func(x,varargin{:});
else
s = s + 2*func(x,varargin{:});
end
end
s = s + func(xn,varargin{:});
I = ((xn-x0)*s)/(3*n);
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!