Register to reply

Composite Simpsons 1/3 matlab code

by haz
Tags: 1 or 3, code, composite, matlab, simpsons
Share this thread:
May10-14, 03:30 AM
P: 4
hey guys,
So I'm working on a matlab function that uses simpsons 1/3 rule to find an integral.
This is what I have done so far, but I'm not 100% confident..
If anyone would be able to have a look at give me some tips that would be very much appreciated.

function [ I ] = simpsons3( func,a,b,n )
%Finds estimate integral from a to b of function using simpson 1/3 rule

% % func = function
% % a = lower limit
% % b = upper limit
% % n=number of segments used for integration
% % I = integral estimate

h = (b-a)/(n-1);
sumE = 0;
for i = a+2*h:h:b-2*h
sumE = sumE + func(i);
sumO = 0;
for i = a+h:h:b-h
sumO = sumO + func(i);
I = (h/3)*(func(a)+4*sumE+2*sumO+func(b));
Phys.Org News Partner Engineering news on
Catching grease to cut grill pollution
Researchers develop tool to predict the level of driver discomfort caused by LED lighting
New inexpensive and easy to implement computer software provides real-time and highly accurate data on traffic

Register to reply

Related Discussions
Help with MATLAB code; discrepancy between graph max and Matlab's max Math & Science Software 1
Please I need a Help with matlab code (Controlling the LEGO NXT Using MatLab) Math & Science Software 5
Matlab R2011a's new feature: portable C/C++ code directly from MATLAB Math & Science Software 1
Want MATLAB code Electrical Engineering 4
MATLAB code help please... Math & Science Software 2