Intergration of expotential function using simpsons rule
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!