this question is for the numerical integrators out there ...

hello everyone I'm trying to write 1D newton-cotes integral but keep on getting pretty lousy results after consulting with my friend I got to the conclusion that maybe i have some problem with the theory part of my code .
can anyone tell me if I can use two different type newton_cotes rules in the same integral for example i have 6 intervals and of course 6 samples (sample= Function(interval))
and i want to integrate it with 5 nodes or less (for example Simpson 3/8 ~~ 5 nodes , trpez ~~ 2 nodes ) can i use them both in the same time (samples 1 2 3 4 5 with Simpson 3/8 and 5 6 Trapez )
is it OK ? can someone confirm it ? I didn't find info on that anywhere on the web
thank you for your help ! I'm adding my code so you can with it if you want
Matan Fihman
% function [ result ] = EqualySpaced(interval,sample )
%interval - vector for the location on the X axis where the user took messurments
%sample - vector of the taken messurments .
%we assumed that the user
%will sample the dimension by some kind of equaly spaced interval
%hance that length(sample)=length(interval)
%for example : interval = a:h:b , sample = function(sample)<-- vector
L=length(interval);IfSum=0;result=0;i=1;
if(L~=length(sample))
error ('not the same dim');
end
h=(interval(L)-interval(1))/(L-1);
while (i<=L-4)
%do bode's rule
i=i+4;
result=result + h*(14/54*(sample(i)+sample(i-4))+64/45*(sample(i-1)+sample(i-3))+24/45*sample(i-2));
end
if ((L-i)==1)
%do trapz on last 2 sampels
IfSum = h*(0.5*(sample(L)+sample(L-1)));
elseif ((L-i)==2)
%do simpson's rule
IfSum = h*(1/3*(sample(L)+sample(L-2))+4/3*sample(L-1));
elseif ((L-i)==3)
%do simpson's 3/8 rule
IfSum = h*(3/8*(sample(L)+sample(L-3))+9/8*(sample(L-1)+sample(L-2)));
end
result=result+IfSum;

Answers (0)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Asked:

on 6 May 2013

Community Treasure Hunt

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

Start Hunting!