Intergration of expotential function using simpsons rule

조회 수: 12 (최근 30일)
Brian Makuza
Brian Makuza 2019년 11월 15일
I try to do intergration using simpsons rule. Each and every time l use the function simprule it gives me error, "undefined function or variable". How could l define the function more than what l did. Below is my code
%SIMPRULE Simpsons rule integration.
% I = SIMPRULE(F, A, B, N) returns Simpsons rule approximation
% for the integral of f(x) from x=A to x=B, using N subintervals,
% where F is a function handle.
f=@exp(x)
a=0
b=1
n=2
I = simprule(f, a, b, n)
h = (b-a) / n;
x = a:h:b; % an array of length n+1
S = 0;
L = 0;
for l = 1:2:n %generates the odd number array
S = S + 4*f(x(l));
end
for j = 2:2:n % generates the even number array
L = L + 2*f(x(j));
end
I = (h/3)*(f(a)+ S + L + f(x(n)));

답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by