how to program integration method with a variable step ?
Show older comments
Hello,
Please I nedd your help, I spent a lot of time searching how to make a variable step on an integration method like trapeze or simpson, I tried to variate h the step on the area of the signal. I use this code , but I'm confused !
The purpose is to variate h to not have the same h for N subdivisions. h=(b-a)/N ( fixed sample)
Iexa = (2*(sqrt(9)-sqrt(5)));
alpha = 0;
beta = 4;
%t=linspace(0,4);
%l=rand(N,1)
h = alpha + ((beta-alpha)./N).*rand(N,1);
% for j=1:N
% h = (beta-alpha).*rand(0,1);
% % h=(t(j+1)-t(j));
% % t=t+j;
% end
x = [alpha:h:beta];
f = inline('1./sqrt(5+x)','x');
Isim =zeros(N,1);
for i=1:N
Isim= Isim+h*(1/6*f(x(i))+2/3*f((x(i)+x(i+1))/2)+1/6*f(x(i+1)));
end
Isim
Esim= abs(Iexa - Isim)
The obtained values of Isim aren't raisonable. Do you have an Idea to make a non uniform sampling on integral method ? Thank you
Accepted Answer
More Answers (0)
Categories
Find more on Numerical Integration and Differentiation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!