simpsons 1/3 rule calculating error
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Calculus en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!