Intergration of expotential function using simpsons rule
조회 수: 12 (최근 30일)
이전 댓글 표시
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
답변 (0개)
참고 항목
카테고리
Help Center 및 File 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!