how to program integration method with a variable step ?
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Numerical Integration and Differentiation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!